Skip to content

Commit 7ab889f

Browse files
ndufresnemchehab
authored andcommitted
media: rkvdec: h264: Fix dpb_valid implementation
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 <[email protected]> Reviewed-by: Sebastian Fricke <[email protected]> Reviewed-by: Ezequiel Garcia <[email protected]> Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Mauro Carvalho Chehab <[email protected]>
1 parent 9998943 commit 7ab889f

File tree

1 file changed

+24
-9
lines changed

1 file changed

+24
-9
lines changed

drivers/staging/media/rkvdec/rkvdec-h264.c

Lines changed: 24 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,7 @@ struct rkvdec_h264_run {
112112
const struct v4l2_ctrl_h264_sps *sps;
113113
const struct v4l2_ctrl_h264_pps *pps;
114114
const struct v4l2_ctrl_h264_scaling_matrix *scaling_matrix;
115+
int ref_buf_idx[V4L2_H264_NUM_DPB_ENTRIES];
115116
};
116117

117118
struct rkvdec_h264_ctx {
@@ -725,6 +726,26 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx,
725726
}
726727
}
727728

729+
static void lookup_ref_buf_idx(struct rkvdec_ctx *ctx,
730+
struct rkvdec_h264_run *run)
731+
{
732+
const struct v4l2_ctrl_h264_decode_params *dec_params = run->decode_params;
733+
u32 i;
734+
735+
for (i = 0; i < ARRAY_SIZE(dec_params->dpb); i++) {
736+
struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
737+
const struct v4l2_h264_dpb_entry *dpb = run->decode_params->dpb;
738+
struct vb2_queue *cap_q = &m2m_ctx->cap_q_ctx.q;
739+
int buf_idx = -1;
740+
741+
if (dpb[i].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
742+
buf_idx = vb2_find_timestamp(cap_q,
743+
dpb[i].reference_ts, 0);
744+
745+
run->ref_buf_idx[i] = buf_idx;
746+
}
747+
}
748+
728749
static void assemble_hw_rps(struct rkvdec_ctx *ctx,
729750
struct rkvdec_h264_run *run)
730751
{
@@ -762,7 +783,7 @@ static void assemble_hw_rps(struct rkvdec_ctx *ctx,
762783

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

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

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

785804
set_ps_field(hw_rps, DPB_INFO(i, j),
786805
idx | dpb_valid << 4);
@@ -859,13 +878,8 @@ get_ref_buf(struct rkvdec_ctx *ctx, struct rkvdec_h264_run *run,
859878
unsigned int dpb_idx)
860879
{
861880
struct v4l2_m2m_ctx *m2m_ctx = ctx->fh.m2m_ctx;
862-
const struct v4l2_h264_dpb_entry *dpb = run->decode_params->dpb;
863881
struct vb2_queue *cap_q = &m2m_ctx->cap_q_ctx.q;
864-
int buf_idx = -1;
865-
866-
if (dpb[dpb_idx].flags & V4L2_H264_DPB_ENTRY_FLAG_ACTIVE)
867-
buf_idx = vb2_find_timestamp(cap_q,
868-
dpb[dpb_idx].reference_ts, 0);
882+
int buf_idx = run->ref_buf_idx[dpb_idx];
869883

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

11031117
assemble_hw_scaling_list(ctx, &run);
11041118
assemble_hw_pps(ctx, &run);
1119+
lookup_ref_buf_idx(ctx, &run);
11051120
assemble_hw_rps(ctx, &run);
11061121
config_registers(ctx, &run);
11071122

0 commit comments

Comments
 (0)