From patchwork Tue Jun 18 19:46:31 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jonas Karlman X-Patchwork-Id: 806202 Received: from smtp.forwardemail.net (smtp.forwardemail.net [149.28.215.223]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 5C72718132A for ; Tue, 18 Jun 2024 19:47:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=149.28.215.223 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740070; cv=none; b=pyUty5lQv+hQdwy7FjI45uI6HxV//G31a0X9b2aYJqmyjD1jzrJGlGolacYKhtgKjpjbYOhWHpXedZHl6qXR0cad3kflVyBJvD/dk+dgbu4rJU1XXFd/OhyfcEfTtMzaIgD3/xmMovpkvwWzkfpY8gNw7ZFwsGyQcoyZL/KYuws= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718740070; c=relaxed/simple; bh=kn6TDSN1cOq8rmDaetJoGdLxyyLqzv1K0aFZgKEothM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=GxTFu9CfNH58QYXdFxjUchJ/id79vgh5cic2oizGyYU39FqOKgAOFHa4qUPyLHNRrqQzv7rZpTeoH2Q2H8jpKGfmAFEWjVLeCU+TVhtCb8N8WvAUIlMcX9CkwjZRuhRjpkWz2QydY4rPIh529DArnl+v+njBXVuLMvGLD02Rkd8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kwiboo.se; spf=pass smtp.mailfrom=fe-bounces.kwiboo.se; dkim=pass (2048-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b=voF/aOBp; arc=none smtp.client-ip=149.28.215.223 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=kwiboo.se Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=fe-bounces.kwiboo.se Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kwiboo.se header.i=@kwiboo.se header.b="voF/aOBp" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kwiboo.se; h=Content-Transfer-Encoding: MIME-Version: References: In-Reply-To: Message-ID: Date: Subject: Cc: To: From; q=dns/txt; s=fe-e1b5cab7be; t=1718740047; bh=jH6RohZozfKa9VCBBYd0/7XL1yNeMYaa06+5jZ6rl28=; b=voF/aOBp3bJsRLbYPrhtrQJZYHHbsohfhODZSVtprCBlaNGWf8wKb1dBw8tc3pmNGcceNOXXj IvB86ECMmonTuhFTm3igVs3f3MtOz44gk9RCI5SL2VLWK1DMlSEkcdyImWDekigVxsm/Xu6n1Zn Q0Cfe6cNryEe2Oiae3qeqIpXrchBeVktBNYLsda6coLxhXsAIKiczyS30bpZdEX/kndetyCfN5m LB7hmE9PikXrioAa35K1yIqy7stJFqfpwXoQ3jZYBbp/1g4JXvEIANamBoclNwDiNetU6erqvuu cwK2INRmOn2QrzgjoFDHPqm5u6Sj9Pfu0h29QkDDJzlg== From: Jonas Karlman To: Ezequiel Garcia , Mauro Carvalho Chehab , Hans Verkuil , "Greg Kroah-Hartman" Cc: Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Sebastian Fricke , Christopher Obbard , Detlev Casanova , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman Subject: [PATCH v5 07/10] media: rkvdec: Extract decoded format enumeration into helper Date: Tue, 18 Jun 2024 19:46:31 +0000 Message-ID: <20240618194647.742037-8-jonas@kwiboo.se> X-Mailer: git-send-email 2.45.2 In-Reply-To: <20240618194647.742037-1-jonas@kwiboo.se> References: <20240618194647.742037-1-jonas@kwiboo.se> Precedence: bulk X-Mailing-List: linux-media@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Report-Abuse-To: abuse@forwardemail.net X-Report-Abuse: abuse@forwardemail.net X-Complaints-To: abuse@forwardemail.net X-ForwardEmail-Version: 0.4.40 X-ForwardEmail-Sender: rfc822; jonas@kwiboo.se, smtp.forwardemail.net, 149.28.215.223 X-ForwardEmail-ID: 6671e44c64ade33c90059fef Add a rkvdec_is_valid_fmt() helper that check if a fourcc is a supported CAPTURE format, and a rkvdec_enum_decoded_fmt() helper that enumerates valid formats. This moves current code into helper functions in preparation for adding CAPTURE format filtering and validation in next patch. Signed-off-by: Jonas Karlman Reviewed-by: Nicolas Dufresne Tested-by: Nicolas Dufresne Tested-by: Christopher Obbard --- v5: - Update commit message - Collect r-b and t-b tags v4: - Rename rkvdec_decoded_fmts() to rkvdec_enum_decoded_fmt() - Rename rkvdec_valid_fmt() to rkvdec_is_valid_fmt() v3: - New patch drivers/staging/media/rkvdec/rkvdec.c | 49 +++++++++++++++++++-------- 1 file changed, 35 insertions(+), 14 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c index 7e59db3fc24d..efbf9aa578ae 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -27,6 +27,32 @@ #include "rkvdec.h" #include "rkvdec-regs.h" +static u32 rkvdec_enum_decoded_fmt(struct rkvdec_ctx *ctx, int index) +{ + const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc; + + if (WARN_ON(!desc)) + return 0; + + if (index >= desc->num_decoded_fmts) + return 0; + + return desc->decoded_fmts[index]; +} + +static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc) +{ + const struct rkvdec_coded_fmt_desc *desc = ctx->coded_fmt_desc; + unsigned int i; + + for (i = 0; i < desc->num_decoded_fmts; i++) { + if (desc->decoded_fmts[i] == fourcc) + return true; + } + + return false; +} + static void rkvdec_fill_decoded_pixfmt(struct rkvdec_ctx *ctx, struct v4l2_pix_format_mplane *pix_mp) { @@ -52,8 +78,10 @@ static void rkvdec_reset_fmt(struct rkvdec_ctx *ctx, struct v4l2_format *f, static void rkvdec_reset_decoded_fmt(struct rkvdec_ctx *ctx) { struct v4l2_format *f = &ctx->decoded_fmt; + u32 fourcc; - rkvdec_reset_fmt(ctx, f, ctx->coded_fmt_desc->decoded_fmts[0]); + fourcc = rkvdec_enum_decoded_fmt(ctx, 0); + rkvdec_reset_fmt(ctx, f, fourcc); f->type = V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; f->fmt.pix_mp.width = ctx->coded_fmt.fmt.pix_mp.width; f->fmt.pix_mp.height = ctx->coded_fmt.fmt.pix_mp.height; @@ -244,7 +272,6 @@ static int rkvdec_try_capture_fmt(struct file *file, void *priv, struct v4l2_pix_format_mplane *pix_mp = &f->fmt.pix_mp; struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); const struct rkvdec_coded_fmt_desc *coded_desc; - unsigned int i; /* * The codec context should point to a coded format desc, if the format @@ -255,13 +282,8 @@ static int rkvdec_try_capture_fmt(struct file *file, void *priv, if (WARN_ON(!coded_desc)) return -EINVAL; - for (i = 0; i < coded_desc->num_decoded_fmts; i++) { - if (coded_desc->decoded_fmts[i] == pix_mp->pixelformat) - break; - } - - if (i == coded_desc->num_decoded_fmts) - pix_mp->pixelformat = coded_desc->decoded_fmts[0]; + if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat)) + pix_mp->pixelformat = rkvdec_enum_decoded_fmt(ctx, 0); /* Always apply the frmsize constraint of the coded end. */ pix_mp->width = max(pix_mp->width, ctx->coded_fmt.fmt.pix_mp.width); @@ -425,14 +447,13 @@ static int rkvdec_enum_capture_fmt(struct file *file, void *priv, struct v4l2_fmtdesc *f) { struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv); + u32 fourcc; - if (WARN_ON(!ctx->coded_fmt_desc)) - return -EINVAL; - - if (f->index >= ctx->coded_fmt_desc->num_decoded_fmts) + fourcc = rkvdec_enum_decoded_fmt(ctx, f->index); + if (!fourcc) return -EINVAL; - f->pixelformat = ctx->coded_fmt_desc->decoded_fmts[f->index]; + f->pixelformat = fourcc; return 0; }