Skip to content

Commit

Permalink
media: rkvdec: h264: Fix dpb_valid implementation
Browse files Browse the repository at this point in the history
[ Upstream commit 7ab889f ]

The ref builder only provided references that are marked as valid in the
dpb. Thus the current implementation of dpb_valid would always set the
flag to 1. This is not representing missing frames (this is called
'non-existing' pictures in the spec). In some context, these non-existing
pictures still need to occupy a slot in the reference list according to
the spec.

Fixes: cd33c83 ("media: rkvdec: Add the rkvdec driver")
Signed-off-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Reviewed-by: Sebastian Fricke <sebastian.fricke@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>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
ndufresne authored and gregkh committed Jun 9, 2022
1 parent 82239e3 commit b4805a7
Showing 1 changed file with 24 additions and 9 deletions.
33 changes: 24 additions & 9 deletions drivers/staging/media/rkvdec/rkvdec-h264.c
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ struct rkvdec_h264_run {
const struct v4l2_ctrl_h264_sps *sps;
const struct v4l2_ctrl_h264_pps *pps;
const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
int ref_buf_idx[V4L2_H264_NUM_DPB_ENTRIES];
};

struct rkvdec_h264_ctx {
Expand Down Expand Up @@ -725,6 +726,26 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,
}
}

static void lookup_ref_buf_idx(struct rkvdec_ctx *ctx,
struct rkvdec_h264_run *run)
{
const struct v4l2_ctrl_h264_decode_params *dec_params = run->decode_params;
u32 i;

for (i = 0; i < ARRAY_SIZE(dec_params->dpb); i++) {
struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
const struct v4l2_h264_dpb_entry *dpb = run->decode_params->dpb;
struct vb2_queue *cap_q = &m2m_ctx->cap_q_ctx.q;
int buf_idx = -1;

if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
buf_idx = vb2_find_timestamp(cap_q,
dpb[i].reference_ts, 0);

run->ref_buf_idx[i] = buf_idx;
}
}

static void assemble_hw_rps(struct rkvdec_ctx *ctx,
struct rkvdec_h264_run *run)
{
Expand Down Expand Up @@ -762,7 +783,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,

for (j = 0; j < RKVDEC_NUM_REFLIST; j++) {
for (i = 0; i < h264_ctx->reflists.num_valid; i++) {
u8 dpb_valid = 0;
bool dpb_valid = run->ref_buf_idx[i] >= 0;
u8 idx = 0;

switch (j) {
Expand All @@ -779,8 +800,6 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,

if (idx >= ARRAY_SIZE(dec_params->dpb))
continue;
dpb_valid = !!(dpb[idx].flags &
V4L2_H264_DPB_ENTRY_FLAG_ACTIVE);

set_ps_field(hw_rps, DPB_INFO(i, j),
idx | dpb_valid << 4);
Expand Down Expand Up @@ -859,13 +878,8 @@ get_ref_buf(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run,
unsigned int dpb_idx)
{
struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
const struct v4l2_h264_dpb_entry *dpb = run->decode_params->dpb;
struct vb2_queue *cap_q = &m2m_ctx->cap_q_ctx.q;
int buf_idx = -1;

if (dpb[dpb_idx].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
buf_idx = vb2_find_timestamp(cap_q,
dpb[dpb_idx].reference_ts, 0);
int buf_idx = run->ref_buf_idx[dpb_idx];

/*
* If a DPB entry is unused or invalid, address of current destination
Expand Down Expand Up @@ -1102,6 +1116,7 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx)

assemble_hw_scaling_list(ctx, &run);
assemble_hw_pps(ctx, &run);
lookup_ref_buf_idx(ctx, &run);
assemble_hw_rps(ctx, &run);
config_registers(ctx, &run);

Expand Down

0 comments on commit b4805a7

Please sign in to comment.