From patchwork Tue Feb 25 09:40:28 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sebastian Fricke X-Patchwork-Id: 13989704 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 99063C197BF for ; Tue, 25 Feb 2025 10:02:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:Cc:To:In-Reply-To:References:Message-Id :MIME-Version:Subject:Date:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Tzq7LoAGwn8w5hEo8oY6vuQwJRi13EiUbbftDwIAL3g=; b=chdgyqZLAGlC5V Ek23uyvkATOitgTKAmoz7nNeFWoM0E7u6PmATzM7Rej2I70v+98N3aFK5nHn2lSML+fVrSGsQkDpa cXC1DgiTzyNQ4tDh3QObawO6tU6JQDUg5biiQe6EgCGIYbpAvWhfkYQ1FB5UpZ7Mo0X8NLq1MnTGg duSr28tn0G4wgMyRE53yUeGeuP+348A6e/a3KjKP1+pelJVxLnOlC6aS7e0YR5O4NAoWWlcep7Npn aIIs8WzorQ4vSCJgOZurTPERYNVPnTYEyIraBLeYOqNFiM9Jqkzv5I913WabQWG+GK28CrBc/DYXp 7PUNlyhLf6wlq3OPm8Jg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.98 #2 (Red Hat Linux)) id 1tmrlI-0000000GjMs-4205; Tue, 25 Feb 2025 10:02:00 +0000 Received: from sender4-pp-f112.zoho.com ([136.143.188.112]) by bombadil.infradead.org with esmtps (Exim 4.98 #2 (Red Hat Linux)) id 1tmrRs-0000000Gegy-153d for linux-rockchip@lists.infradead.org; Tue, 25 Feb 2025 09:41:57 +0000 ARC-Seal: i=1; a=rsa-sha256; t=1740476511; cv=none; d=zohomail.com; s=zohoarc; b=DGdk2GJrDFkoqvDfsUsLvzL1IltRpKTGufxgRf1CV/yn+Z5HL9Ug59pZLXZHFe9FLvlvU8wKWeseKb9pfeCepo4Ahv02phLK3dUkhUfZAkGmhU8gLSBtpUA0ujaGBz5lA2uD9P3Pl2y4lMfHSAhDanwPM2de6d68clXYPqc67eQ= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1740476511; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:In-Reply-To:MIME-Version:Message-ID:References:Subject:Subject:To:To:Message-Id:Reply-To; bh=f813he9CIjQ1Ioaz2tbittxRpzX26TEh6AGlGCMqNmI=; b=CNCFPSGtUq4Mi0w4jeCu25aBm45YMrvRF4Mjau/PxUlwXhStzH0JYUjE0UbmtAm0HGkxoLY35YRFu5+NSJfDdB2I4vnkbCZg+v+6fdkG1/c7AmZ4mTdPFx3O3leIBKl8MF2B91pLYbO0ipB5mP1I1XlQoVXqa0iV7syrC2BUinE= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass header.i=collabora.com; spf=pass smtp.mailfrom=sebastian.fricke@collabora.com; dmarc=pass header.from= DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; t=1740476511; s=zohomail; d=collabora.com; i=sebastian.fricke@collabora.com; h=From:From:Date:Date:Subject:Subject:MIME-Version:Content-Type:Content-Transfer-Encoding:Message-Id:Message-Id:References:In-Reply-To:To:To:Cc:Cc:Reply-To; bh=f813he9CIjQ1Ioaz2tbittxRpzX26TEh6AGlGCMqNmI=; b=I5YRzBa7NwjWTmk1SrKuHZby0NGCcO6Ht4j8OsxotMESFWA1b0zjFtdvPdPWcQC9 ajybQeth5P4M9C3VmpL2DmyPDdR2J0KxQCy8MoT5pOt8Z0ty4PvsVX/kxgfqKtZwzL/ HuXonthNdqOZOLBCP0a0VQOTh2bbctWpdeEBKMdo= Received: by mx.zohomail.com with SMTPS id 1740476508950172.31338096378624; Tue, 25 Feb 2025 01:41:48 -0800 (PST) From: Sebastian Fricke Date: Tue, 25 Feb 2025 10:40:28 +0100 Subject: [PATCH v7 07/12] media: rkvdec: Extract decoded format enumeration into helper MIME-Version: 1.0 Message-Id: <20250225-rkvdec_h264_high10_and_422_support-v7-7-7992a68a4910@collabora.com> References: <20250225-rkvdec_h264_high10_and_422_support-v7-0-7992a68a4910@collabora.com> In-Reply-To: <20250225-rkvdec_h264_high10_and_422_support-v7-0-7992a68a4910@collabora.com> To: Mauro Carvalho Chehab , Ezequiel Garcia , Greg Kroah-Hartman , Hans Verkuil , Boris Brezillon Cc: linux-media@vger.kernel.org, linux-kernel@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, Mauro Carvalho Chehab , Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Detlev Casanova , Dan Carpenter , Jonas Karlman , Christopher Obbard X-Mailer: b4 0.14.2 X-Developer-Signature: v=1; a=ed25519-sha256; t=1740476426; l=3784; i=sebastian.fricke@collabora.com; s=linux-media; h=from:subject:message-id; bh=RSQZQqZZVnoCe1gog6U2AiCd3QpQqZlEPDJjUoDLNn4=; b=yLSOBoJ0o4imr0nBKyr3dC4VXh9atoi5XaaWVL/0JiE8WIq58cpMc9E9kAydULjGFYSRZnpkppfs Rz5Hz9jvDlKXxgx8/4qoqdbeyKYID1YxzTdITFyRlGuysv4jnu/4 X-Developer-Key: i=sebastian.fricke@collabora.com; a=ed25519; pk=pYXedPwrTtErcj7ERYeo/IpTrpe4QbJuEzSB52fslBg= X-ZohoMailClient: External X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20250225_014156_371131_EA5A5CAD X-CRM114-Status: GOOD ( 15.11 ) X-BeenThere: linux-rockchip@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Upstream kernel work for Rockchip platforms List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-rockchip" Errors-To: linux-rockchip-bounces+linux-rockchip=archiver.kernel.org@lists.infradead.org From: Jonas Karlman 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 --- 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 1f8f98cf91dc205f4a9da2712c81e90b726a6e57..52e64b399dcc4a0c028cac908c0b1ceb49956c5f 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; }