From: Boris Brezillon <boris.brezillon@collabora.com> To: Mauro Carvalho Chehab <mchehab@kernel.org>, Hans Verkuil <hans.verkuil@cisco.com>, Laurent Pinchart <laurent.pinchart@ideasonboard.com>, Sakari Ailus <sakari.ailus@iki.fi>, linux-media@vger.kernel.org Cc: Philipp Zabel <p.zabel@pengutronix.de>, Ezequiel Garcia <ezequiel@collabora.com>, Nicolas Dufresne <nicolas.dufresne@collabora.com>, Tomasz Figa <tfiga@chromium.org>, Jonas Karlman <jonas@kwiboo.se>, Francois Buergisser <fbuergisser@google.com>, Boris Brezillon <boris.brezillon@collabora.com> Subject: [PATCH 3/3] media: hantro: h264: Fix the frame_num wraparound case Date: Mon, 9 Sep 2019 09:28:15 +0200 Message-ID: <20190909072815.23981-3-boris.brezillon@collabora.com> (raw) In-Reply-To: <20190909072815.23981-1-boris.brezillon@collabora.com> Step '8.2.4.1 Decoding process for picture numbers' was missing in the reflist creation logic, leading to invalid P reflists when a ->frame_num wraparound happens. Fixes: a9471e25629b ("media: hantro: Add core bits to support H264 decoding") Reported-by: Francois Buergisser <fbuergisser@google.com> Signed-off-by: Boris Brezillon <boris.brezillon@collabora.com> --- drivers/staging/media/hantro/hantro_h264.c | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/drivers/staging/media/hantro/hantro_h264.c b/drivers/staging/media/hantro/hantro_h264.c index 881d73977ff6..e3f757a7de34 100644 --- a/drivers/staging/media/hantro/hantro_h264.c +++ b/drivers/staging/media/hantro/hantro_h264.c @@ -271,6 +271,7 @@ struct hantro_h264_reflist_builder { const struct v4l2_h264_dpb_entry *dpb; s32 pocs[HANTRO_H264_DPB_SIZE]; u8 unordered_reflist[HANTRO_H264_DPB_SIZE]; + int frame_nums[HANTRO_H264_DPB_SIZE]; s32 curpoc; u8 num_valid; }; @@ -294,13 +295,20 @@ static void init_reflist_builder(struct hantro_ctx *ctx, struct hantro_h264_reflist_builder *b) { + const struct v4l2_ctrl_h264_slice_params *slice_params; const struct v4l2_ctrl_h264_decode_params *dec_param; + const struct v4l2_ctrl_h264_sps *sps; struct vb2_v4l2_buffer *buf = hantro_get_dst_buf(ctx); const struct v4l2_h264_dpb_entry *dpb = ctx->h264_dec.dpb; struct vb2_queue *cap_q = &ctx->fh.m2m_ctx->cap_q_ctx.q; + int cur_frame_num, max_frame_num; unsigned int i; dec_param = ctx->h264_dec.ctrls.decode; + slice_params = &ctx->h264_dec.ctrls.slices[0]; + sps = ctx->h264_dec.ctrls.sps; + max_frame_num = 1 << (sps->log2_max_frame_num_minus4 + 4); + cur_frame_num = slice_params->frame_num; memset(b, 0, sizeof(*b)); b->dpb = dpb; @@ -318,6 +326,18 @@ init_reflist_builder(struct hantro_ctx *ctx, continue; buf = to_vb2_v4l2_buffer(vb2_get_buffer(cap_q, buf_idx)); + + /* + * Handle frame_num wraparound as described in section + * '8.2.4.1 Decoding process for picture numbers' of the spec. + * TODO: This logic will have to be adjusted when we start + * supporting interlaced content. + */ + if (dpb[i].frame_num > cur_frame_num) + b->frame_nums[i] = (int)dpb[i].frame_num - max_frame_num; + else + b->frame_nums[i] = dpb[i].frame_num; + b->pocs[i] = get_poc(buf->field, dpb[i].top_field_order_cnt, dpb[i].bottom_field_order_cnt); b->unordered_reflist[b->num_valid] = i; @@ -353,7 +373,8 @@ static int p_ref_list_cmp(const void *ptra, const void *ptrb, const void *data) * ascending order. */ if (!(a->flags & V4L2_H264_DPB_ENTRY_FLAG_LONG_TERM)) - return HANTRO_CMP(b->frame_num, a->frame_num); + return HANTRO_CMP(builder->frame_nums[idxb], + builder->frame_nums[idxa]); return HANTRO_CMP(a->pic_num, b->pic_num); } -- 2.21.0
next prev parent reply index Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-09-09 7:28 [PATCH 1/3] media: hantro: h264: Fix a comment in b1_ref_list_cmp() Boris Brezillon 2019-09-09 7:28 ` [PATCH 2/3] media: hantro: h264: Rename POC_CMP() into HANTRO_CMP() Boris Brezillon 2019-09-18 5:03 ` Francois Buergisser 2019-09-18 6:19 ` Tomasz Figa 2019-09-09 7:28 ` Boris Brezillon [this message] 2019-09-09 7:31 ` [PATCH 3/3] media: hantro: h264: Fix the frame_num wraparound case Boris Brezillon 2019-09-09 8:51 ` Philipp Zabel 2019-09-18 5:04 ` Francois Buergisser 2019-09-18 6:29 ` Tomasz Figa 2019-09-18 5:03 ` [PATCH 1/3] media: hantro: h264: Fix a comment in b1_ref_list_cmp() Francois Buergisser 2019-09-18 6:18 ` Tomasz Figa
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=20190909072815.23981-3-boris.brezillon@collabora.com \ --to=boris.brezillon@collabora.com \ --cc=ezequiel@collabora.com \ --cc=fbuergisser@google.com \ --cc=hans.verkuil@cisco.com \ --cc=jonas@kwiboo.se \ --cc=laurent.pinchart@ideasonboard.com \ --cc=linux-media@vger.kernel.org \ --cc=mchehab@kernel.org \ --cc=nicolas.dufresne@collabora.com \ --cc=p.zabel@pengutronix.de \ --cc=sakari.ailus@iki.fi \ --cc=tfiga@chromium.org \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
Linux-Media Archive on lore.kernel.org Archives are clonable: git clone --mirror https://lore.kernel.org/linux-media/0 linux-media/git/0.git # If you have public-inbox 1.1+ installed, you may # initialize and index your mirror using the following commands: public-inbox-init -V2 linux-media linux-media/ https://lore.kernel.org/linux-media \ linux-media@vger.kernel.org public-inbox-index linux-media Example config snippet for mirrors Newsgroup available over NNTP: nntp://nntp.lore.kernel.org/org.kernel.vger.linux-media AGPL code for this site: git clone https://public-inbox.org/public-inbox.git