From patchwork Wed Jul 1 21:56:21 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 11637377 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D6EE014E3 for ; Wed, 1 Jul 2020 21:56:36 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id AD4BA2077D for ; Wed, 1 Jul 2020 21:56:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="t85NaZED"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b="WSi8BJTU" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD4BA2077D Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=kwiboo.se Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:MIME-Version:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:To:References:In-Reply-To:Message-Id:Date:Subject: From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=e3FTaiaXYLgS5UJx8ha1z/IIJ2PiF/Qy3XkA014Me1k=; b=t85NaZED1WWofIR/VKfJA+tG6u 6jejzV6q03Mr55ayLKF+8AM3W9q9EXsbAzZ8vjM+mGy0vUt7CA3CPXnpGFkhCw4oJ57gL1cASsKK/ NfgRR92GPVF6U+gRwgHYbN/BVAgHhPisuZgxiAv6ux6+aYf5MzLHrwwL0vzBvH2/Wc/M7GK/hvbEQ Xr3+ARcSxqPqBFs+bczVCRBgub+SgRjYoaUiQR+JlsxakcCNJ1X+0Dq+KRAj0dGUbK1NsC3gNjSl3 5tkmn6pnkMb+GOHa+v0Jqs6zjw1ZfOMsIg9ex0wD3I+x9ussDyNKJ9M7A1SMT3/hdgUeQ/MFxIkS+ w+cJLHsA==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqkiV-00084x-Ha; Wed, 01 Jul 2020 21:56:31 +0000 Received: from o1.b.az.sendgrid.net ([208.117.55.133]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jqkiO-0007yn-HO for linux-rockchip@lists.infradead.org; Wed, 01 Jul 2020 21:56:27 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=from:subject:in-reply-to:references:to:cc:content-type: content-transfer-encoding; s=001; bh=hPL/kgQTz6wlFRy8GpHOwzP9TJx6MI3KcPavoqbKOOc=; b=WSi8BJTUy3xDpcNlZN5tgfE1peEZwGWXPR8iKHe6BqAwMIL3afNAX6UTQthDkJGX9Lk7 WKl/9aE5gP4U4tiqW2w3Qh7W8S2yrj2ayYFlPTWGRA5muHaRKVU9zc9ahIY6WQCGfgNaT/ I740X3GHA6TgaYdhueZaThZOdgN1oFw+8= Received: by filterdrecv-p3iad2-5b55dcd864-xvj6x with SMTP id filterdrecv-p3iad2-5b55dcd864-xvj6x-20-5EFD0685-3B 2020-07-01 21:56:21.873945324 +0000 UTC m=+449225.981582369 Received: from bionic.localdomain (unknown) by ismtpd0001p1lon1.sendgrid.net (SG) with ESMTP id tbZBENmMR5K2F9HM17zllg Wed, 01 Jul 2020 21:56:21.586 +0000 (UTC) From: Jonas Karlman Subject: [PATCH 3/9] media: rkvdec: h264: Fix pic width and height in mbs Date: Wed, 01 Jul 2020 21:56:21 +0000 (UTC) Message-Id: <20200701215616.30874-4-jonas@kwiboo.se> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200701215616.30874-1-jonas@kwiboo.se> References: <20200701215616.30874-1-jonas@kwiboo.se> X-SG-EID: TdbjyGynYnRZWhH+7lKUQJL+ZxmxpowvO2O9SQF5CwCVrYgcwUXgU5DKUU3QxAfZekEeQsTe+RrMu3cja6a0h46KlexVvyedR2tUqgjVmM/ILFuMT+pt9FyPU3oqNPS8WalWdE9qEGVvQSMehNe2haUM8g4S6hR000xVYRiSvFYvH5oeMB1A8rwFwFHkpOk9mBIzJiMJO1ijbTh3awbe2/Wgzly9mwjAXJl4OmV0Ujt7wmcT5W9bvUiAldmvWcvD4F7EDgWU4n7AhFRZRIqdOg== To: linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-kernel@vger.kernel.org X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200701_175624_676841_1EB61E3C X-CRM114-Status: GOOD ( 13.34 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [208.117.55.133 listed in list.dnswl.org] -0.0 RCVD_IN_MSPIKE_H2 RBL: Average reputation (+2) [208.117.55.133 listed in wl.mailspike.net] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid 0.0 UNPARSEABLE_RELAY Informational: message has unparseable relay lines X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Alexandre Courbot , Jonas Karlman , Tomasz Figa , Hans Verkuil , Nicolas Dufresne , Ezequiel Garcia MIME-Version: 1.0 Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+patchwork-linux-rockchip=patchwork.kernel.org@lists.infradead.org The width and height in mbs is currently configured based on OUTPUT buffer resolution, this works for frame pictures but can cause issues for field pictures or when frmsize step_width is changed to support 10-bit decoding. When frame_mbs_only_flag is 0 the height in mbs should be height of the field instead of height of frame. Validate pic_width_in_mbs_minus1 and pic_height_in_map_units_minus1 against CAPTURE buffer resolution and use these values to configure HW. Signed-off-by: Jonas Karlman --- drivers/staging/media/rkvdec/rkvdec-h264.c | 44 +++++++++++++++++++--- 1 file changed, 39 insertions(+), 5 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec-h264.c b/drivers/staging/media/rkvdec/rkvdec-h264.c index f0cfed84d60d..c9aebeb8f9b3 100644 --- a/drivers/staging/media/rkvdec/rkvdec-h264.c +++ b/drivers/staging/media/rkvdec/rkvdec-h264.c @@ -672,8 +672,8 @@ static void assemble_hw_pps(struct rkvdec_ctx *ctx, LOG2_MAX_PIC_ORDER_CNT_LSB_MINUS4); WRITE_PPS(!!(sps->flags & V4L2_H264_SPS_FLAG_DELTA_PIC_ORDER_ALWAYS_ZERO), DELTA_PIC_ORDER_ALWAYS_ZERO_FLAG); - WRITE_PPS(DIV_ROUND_UP(ctx->coded_fmt.fmt.pix_mp.width, 16), PIC_WIDTH_IN_MBS); - WRITE_PPS(DIV_ROUND_UP(ctx->coded_fmt.fmt.pix_mp.height, 16), PIC_HEIGHT_IN_MBS); + WRITE_PPS(sps->pic_width_in_mbs_minus1 + 1, PIC_WIDTH_IN_MBS); + WRITE_PPS(sps->pic_height_in_map_units_minus1 + 1, PIC_HEIGHT_IN_MBS); WRITE_PPS(!!(sps->flags & V4L2_H264_SPS_FLAG_FRAME_MBS_ONLY), FRAME_MBS_ONLY_FLAG); WRITE_PPS(!!(sps->flags & V4L2_H264_SPS_FLAG_MB_ADAPTIVE_FRAME_FIELD), @@ -1058,10 +1058,33 @@ static void rkvdec_h264_stop(struct rkvdec_ctx *ctx) kfree(h264_ctx); } -static void rkvdec_h264_run_preamble(struct rkvdec_ctx *ctx, - struct rkvdec_h264_run *run) +static int validate_sps(struct rkvdec_ctx *ctx, + const struct v4l2_ctrl_h264_sps *sps) +{ + unsigned int width, height; + + if (WARN_ON(!sps)) + return -EINVAL; + + width = (sps->pic_width_in_mbs_minus1 + 1) * 16; + height = (sps->pic_height_in_map_units_minus1 + 1) * 16; + + if (width > ctx->decoded_fmt.fmt.pix_mp.width || + height > ctx->decoded_fmt.fmt.pix_mp.height) { + dev_err(ctx->dev->dev, + "unexpected bitstream resolution %ux%u\n", + width, height); + return -EINVAL; + } + + return 0; +} + +static int rkvdec_h264_run_preamble(struct rkvdec_ctx *ctx, + struct rkvdec_h264_run *run) { struct v4l2_ctrl *ctrl; + int ret; ctrl = v4l2_ctrl_find(&ctx->ctrl_hdl, V4L2_CID_MPEG_VIDEO_H264_DECODE_PARAMS); @@ -1080,6 +1103,12 @@ static void rkvdec_h264_run_preamble(struct rkvdec_ctx *ctx, run->scaling_matrix = ctrl ? ctrl->p_cur.p : NULL; rkvdec_run_preamble(ctx, &run->base); + + ret = validate_sps(ctx, run->sps); + if (ret) + return ret; + + return 0; } static int rkvdec_h264_run(struct rkvdec_ctx *ctx) @@ -1088,8 +1117,13 @@ static int rkvdec_h264_run(struct rkvdec_ctx *ctx) struct rkvdec_dev *rkvdec = ctx->dev; struct rkvdec_h264_ctx *h264_ctx = ctx->priv; struct rkvdec_h264_run run; + int ret; - rkvdec_h264_run_preamble(ctx, &run); + ret = rkvdec_h264_run_preamble(ctx, &run); + if (ret) { + rkvdec_run_postamble(ctx, &run.base); + return ret; + } /* Build the P/B{0,1} ref lists. */ v4l2_h264_init_reflist_builder(&reflist_builder, run.decode_params,