media: verisilicon: Do not set ctx->bit_depth in hantro_try_ctrl()
authorBenjamin Gaignard <benjamin.gaignard@collabora.com>
Mon, 20 Feb 2023 10:48:46 +0000 (10:48 +0000)
committerMauro Carvalho Chehab <mchehab@kernel.org>
Mon, 10 Apr 2023 13:17:36 +0000 (14:17 +0100)
In hantro_try_ctrl() we should only check the values inside
control parameters and not set ctx->bit_depth. That must
be done in controls set function.
Create a set control function for hevc where ctx->bit_depth is
set at the right time.

Signed-off-by: Benjamin Gaignard <benjamin.gaignard@collabora.com>
Reviewed-by: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab@kernel.org>
drivers/media/platform/verisilicon/hantro_drv.c

index b0aeeda..c237253 100644 (file)
@@ -251,11 +251,6 @@ queue_init(void *priv, struct vb2_queue *src_vq, struct vb2_queue *dst_vq)
 
 static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
 {
-       struct hantro_ctx *ctx;
-
-       ctx = container_of(ctrl->handler,
-                          struct hantro_ctx, ctrl_handler);
-
        if (ctrl->id == V4L2_CID_STATELESS_H264_SPS) {
                const struct v4l2_ctrl_h264_sps *sps = ctrl->p_new.p_h264_sps;
 
@@ -274,8 +269,6 @@ static int hantro_try_ctrl(struct v4l2_ctrl *ctrl)
                if (sps->bit_depth_luma_minus8 != 0 && sps->bit_depth_luma_minus8 != 2)
                        /* Only 8-bit and 10-bit are supported */
                        return -EINVAL;
-
-               ctx->bit_depth = sps->bit_depth_luma_minus8 + 8;
        } else if (ctrl->id == V4L2_CID_STATELESS_VP9_FRAME) {
                const struct v4l2_ctrl_vp9_frame *dec_params = ctrl->p_new.p_vp9_frame;
 
@@ -324,6 +317,24 @@ static int hantro_vp9_s_ctrl(struct v4l2_ctrl *ctrl)
        return 0;
 }
 
+static int hantro_hevc_s_ctrl(struct v4l2_ctrl *ctrl)
+{
+       struct hantro_ctx *ctx;
+
+       ctx = container_of(ctrl->handler,
+                          struct hantro_ctx, ctrl_handler);
+
+       switch (ctrl->id) {
+       case V4L2_CID_STATELESS_HEVC_SPS:
+               ctx->bit_depth = ctrl->p_new.p_hevc_sps->bit_depth_luma_minus8 + 8;
+               break;
+       default:
+               return -EINVAL;
+       }
+
+       return 0;
+}
+
 static const struct v4l2_ctrl_ops hantro_ctrl_ops = {
        .try_ctrl = hantro_try_ctrl,
 };
@@ -336,6 +347,11 @@ static const struct v4l2_ctrl_ops hantro_vp9_ctrl_ops = {
        .s_ctrl = hantro_vp9_s_ctrl,
 };
 
+static const struct v4l2_ctrl_ops hantro_hevc_ctrl_ops = {
+       .try_ctrl = hantro_try_ctrl,
+       .s_ctrl = hantro_hevc_s_ctrl,
+};
+
 #define HANTRO_JPEG_ACTIVE_MARKERS     (V4L2_JPEG_ACTIVE_MARKER_APP0 | \
                                         V4L2_JPEG_ACTIVE_MARKER_COM | \
                                         V4L2_JPEG_ACTIVE_MARKER_DQT | \
@@ -470,7 +486,7 @@ static const struct hantro_ctrl controls[] = {
                .codec = HANTRO_HEVC_DECODER,
                .cfg = {
                        .id = V4L2_CID_STATELESS_HEVC_SPS,
-                       .ops = &hantro_ctrl_ops,
+                       .ops = &hantro_hevc_ctrl_ops,
                },
        }, {
                .codec = HANTRO_HEVC_DECODER,