media: hantro: Use H264_SCALING_MATRIX only when required
authorEzequiel Garcia <ezequiel@collabora.com>
Tue, 25 Aug 2020 03:52:44 +0000 (05:52 +0200)
committerMauro Carvalho Chehab <mchehab+huawei@kernel.org>
Tue, 1 Sep 2020 12:13:29 +0000 (14:13 +0200)
Baseline, Main and Extended profiles are specified to
not support a scaling matrix. Also, High profiles
can optionally specify a scaling matrix, using
SPS and PPS NAL units.

To meet this expectation, applications are required to
set the V4L2_CID_MPEG_VIDEO_H264_SCALING_MATRIX control
and set the V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT
flag only when a scaling matrix is specified for a picture.

Implement this on hantro, which has hardware support for this
case.

Signed-off-by: Ezequiel Garcia <ezequiel@collabora.com>
Tested-by: Jonas Karlman <jonas@kwiboo.se>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+huawei@kernel.org>
drivers/staging/media/hantro/hantro_g1_h264_dec.c
drivers/staging/media/hantro/hantro_h264.c

index f9839e9c6da5abb040f5755c7a8a6a858cd3cf27..845bef73d21844bb780132067954b9dad6784c1b 100644 (file)
@@ -59,9 +59,8 @@ static void set_params(struct hantro_ctx *ctx)
        reg = G1_REG_DEC_CTRL2_CH_QP_OFFSET(pps->chroma_qp_index_offset) |
              G1_REG_DEC_CTRL2_CH_QP_OFFSET2(pps->second_chroma_qp_index_offset);
 
-       /* always use the matrix sent from userspace */
-       reg |= G1_REG_DEC_CTRL2_TYPE1_QUANT_E;
-
+       if (pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT)
+               reg |= G1_REG_DEC_CTRL2_TYPE1_QUANT_E;
        if (!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY))
                reg |= G1_REG_DEC_CTRL2_FIELDPIC_FLAG_E;
        vdpu_write_relaxed(vpu, reg, G1_REG_DEC_CTRL2);
index 089bfa9c625b1342d1232429ec2de7c7c0fdddf1..b1bdc00ac26258791965c58125c0b27efca86269 100644 (file)
@@ -197,6 +197,7 @@ assemble_scaling_list(struct hantro_ctx *ctx)
 {
        const struct hantro_h264_dec_ctrls *ctrls = &ctx->h264_dec.ctrls;
        const struct v4l2_ctrl_h264_scaling_matrix *scaling = ctrls->scaling;
+       const struct v4l2_ctrl_h264_pps *pps = ctrls->pps;
        const size_t num_list_4x4 = ARRAY_SIZE(scaling->scaling_list_4x4);
        const size_t list_len_4x4 = ARRAY_SIZE(scaling->scaling_list_4x4[0]);
        const size_t list_len_8x8 = ARRAY_SIZE(scaling->scaling_list_8x8[0]);
@@ -205,6 +206,9 @@ assemble_scaling_list(struct hantro_ctx *ctx)
        const u32 *src;
        int i, j;
 
+       if (!(pps->flags & V4L2_H264_PPS_FLAG_SCALING_MATRIX_PRESENT))
+               return;
+
        for (i = 0; i < num_list_4x4; i++) {
                src = (u32 *)&scaling->scaling_list_4x4[i];
                for (j = 0; j < list_len_4x4 / 4; j++)