From nobody Sat Nov 30 16:48:04 2024 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 9287D189BA4 for ; Mon, 9 Sep 2024 19:26:24 +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=1725909986; cv=none; b=a4OkjriAKbCjKYUbgqBeh4Tbeypd5HNG47vSyCbuH+mjNwwM1d5kn1hOAOJkvplYuXY2g0gS6+v5Y+VSca1zQQMgX4WW5lEjS3OU9nAl+clDf01saIil2wjkoLfPJdHOOc/kdfKopNWmHv9gG7pg44PEnBhmQv3qWfCxrww4hEQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1725909986; c=relaxed/simple; bh=tkE99i3lOnmErRaLwtdFNLjtsxB0HjwXqaOWWSXWU2M=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Rm/Ff1eivmwyPG1VIKNgfbhYSkWRoT8Zkf0Yfq9yVc4JnRoUAEj/oeg1PHRlF8LGs5un0cl4TnYrQCr3vwbs4oaHE47or0jrf9LESmFidGADQ358xFOD6LLc13WsixQ1VsyhA7GqMec/n/oQKSPs+steUQ+GhXEdxKKzcoqkVKQ= 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=EhhqMby/; 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="EhhqMby/" 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=1725909978; bh=4gklXqyktcof8ba4FurfBU5esS2Yxx641ea2Fa/v1L0=; b=EhhqMby/2vQ/JJhXfdW5+/zd8DRVoymOzU6Q//ouhAj9MpGaIQG19UG23XOWWKVsnMiSyXJQK 95i99G1dqp6aPMmoePcptElmCVBmu8orhFKy8OTvcFkFIpM6byg3k6PkYpzmDKzKRCdfOGMLQhJ NXopcT/GpqVJuKOlI537JW/O/xfUQMSiQYjCKa3rfRYlgPVqaG16F/QQ83QSMnayZ/wbhfj+fmo ZvfMk5t+SeD1A16DI1uEFZ0kJxdQ8AOFBYnZ4Kf4tZwp1aDqxmNPGth+j0um/cf7iYWyXHqTk6d C/6rM0vDbxZBT/9didW3tWJ+KzsNt6m5hkK3bZQ647Ew== From: Jonas Karlman To: Sebastian Fricke , Ezequiel Garcia , Mauro Carvalho Chehab , Greg Kroah-Hartman Cc: Alex Bee , Nicolas Dufresne , Benjamin Gaignard , Detlev Casanova , Dan Carpenter , linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org, linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org, Jonas Karlman , Christopher Obbard Subject: [PATCH v6 08/11] media: rkvdec: Add image format concept Date: Mon, 9 Sep 2024 19:25:06 +0000 Message-ID: <20240909192522.1076704-9-jonas@kwiboo.se> X-Mailer: git-send-email 2.46.0 In-Reply-To: <20240909192522.1076704-1-jonas@kwiboo.se> References: <20240909192522.1076704-1-jonas@kwiboo.se> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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: 66df4bd8c680cb8b7d2dc21c Content-Type: text/plain; charset="utf-8" Add an enum rkvdec_image_fmt used to signal an image format, e.g. 4:2:0 8-bit, 4:2:0 10-bit or any. Tag each supported CAPUTRE format with an image format and use this tag to filter out unsupported CAPTURE formats. Signed-off-by: Jonas Karlman Tested-by: Nicolas Dufresne Tested-by: Christopher Obbard Reviewed-by: Nicolas Dufresne --- v6: - Change to use fmt_idx instead of j++ tucked inside a condition (Dan) v5: - Collect t-b tags v4: - Change fmt_opaque into an image format - Split patch into two v3: - New patch --- drivers/staging/media/rkvdec/rkvdec.c | 48 ++++++++++++++++++++------- drivers/staging/media/rkvdec/rkvdec.h | 13 +++++++- 2 files changed, 48 insertions(+), 13 deletions(-) diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/= rkvdec/rkvdec.c index efbf9aa578ae..467fc05b347a 100644 --- a/drivers/staging/media/rkvdec/rkvdec.c +++ b/drivers/staging/media/rkvdec/rkvdec.c @@ -27,26 +27,45 @@ #include "rkvdec.h" #include "rkvdec-regs.h" =20 -static u32 rkvdec_enum_decoded_fmt(struct rkvdec_ctx *ctx, int index) +static inline bool rkvdec_image_fmt_match(enum rkvdec_image_fmt fmt1, + enum rkvdec_image_fmt fmt2) +{ + return fmt1 =3D=3D fmt2 || fmt2 =3D=3D RKVDEC_IMG_FMT_ANY || + fmt1 =3D=3D RKVDEC_IMG_FMT_ANY; +} + +static u32 rkvdec_enum_decoded_fmt(struct rkvdec_ctx *ctx, int index, + enum rkvdec_image_fmt image_fmt) { const struct rkvdec_coded_fmt_desc *desc =3D ctx->coded_fmt_desc; + int fmt_idx =3D -1; + unsigned int i; =20 if (WARN_ON(!desc)) return 0; =20 - if (index >=3D desc->num_decoded_fmts) - return 0; + for (i =3D 0; i < desc->num_decoded_fmts; i++) { + if (!rkvdec_image_fmt_match(desc->decoded_fmts[i].image_fmt, + image_fmt)) + continue; + fmt_idx++; + if (index =3D=3D fmt_idx) + return desc->decoded_fmts[i].fourcc; + } =20 - return desc->decoded_fmts[index]; + return 0; } =20 -static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc) +static bool rkvdec_is_valid_fmt(struct rkvdec_ctx *ctx, u32 fourcc, + enum rkvdec_image_fmt image_fmt) { const struct rkvdec_coded_fmt_desc *desc =3D ctx->coded_fmt_desc; unsigned int i; =20 for (i =3D 0; i < desc->num_decoded_fmts; i++) { - if (desc->decoded_fmts[i] =3D=3D fourcc) + if (rkvdec_image_fmt_match(desc->decoded_fmts[i].image_fmt, + image_fmt) && + desc->decoded_fmts[i].fourcc =3D=3D fourcc) return true; } =20 @@ -80,7 +99,7 @@ static void rkvdec_reset_decoded_fmt(struct rkvdec_ctx *c= tx) struct v4l2_format *f =3D &ctx->decoded_fmt; u32 fourcc; =20 - fourcc =3D rkvdec_enum_decoded_fmt(ctx, 0); + fourcc =3D rkvdec_enum_decoded_fmt(ctx, 0, ctx->image_fmt); rkvdec_reset_fmt(ctx, f, fourcc); f->type =3D V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE; f->fmt.pix_mp.width =3D ctx->coded_fmt.fmt.pix_mp.width; @@ -149,8 +168,11 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls =3D= { .num_ctrls =3D ARRAY_SIZE(rkvdec_h264_ctrl_descs), }; =20 -static const u32 rkvdec_h264_vp9_decoded_fmts[] =3D { - V4L2_PIX_FMT_NV12, +static const struct rkvdec_decoded_fmt_desc rkvdec_h264_vp9_decoded_fmts[]= =3D { + { + .fourcc =3D V4L2_PIX_FMT_NV12, + .image_fmt =3D RKVDEC_IMG_FMT_420_8BIT, + }, }; =20 static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] =3D { @@ -282,8 +304,9 @@ static int rkvdec_try_capture_fmt(struct file *file, vo= id *priv, if (WARN_ON(!coded_desc)) return -EINVAL; =20 - if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat)) - pix_mp->pixelformat =3D rkvdec_enum_decoded_fmt(ctx, 0); + if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat, ctx->image_fmt)) + pix_mp->pixelformat =3D rkvdec_enum_decoded_fmt(ctx, 0, + ctx->image_fmt); =20 /* Always apply the frmsize constraint of the coded end. */ pix_mp->width =3D max(pix_mp->width, ctx->coded_fmt.fmt.pix_mp.width); @@ -400,6 +423,7 @@ static int rkvdec_s_output_fmt(struct file *file, void = *priv, * * Note that this will propagates any size changes to the decoded format. */ + ctx->image_fmt =3D RKVDEC_IMG_FMT_ANY; rkvdec_reset_decoded_fmt(ctx); =20 /* Propagate colorspace information to capture. */ @@ -449,7 +473,7 @@ static int rkvdec_enum_capture_fmt(struct file *file, v= oid *priv, struct rkvdec_ctx *ctx =3D fh_to_rkvdec_ctx(priv); u32 fourcc; =20 - fourcc =3D rkvdec_enum_decoded_fmt(ctx, f->index); + fourcc =3D rkvdec_enum_decoded_fmt(ctx, f->index, ctx->image_fmt); if (!fourcc) return -EINVAL; =20 diff --git a/drivers/staging/media/rkvdec/rkvdec.h b/drivers/staging/media/= rkvdec/rkvdec.h index 633335ebb9c4..6f8cf50c5d99 100644 --- a/drivers/staging/media/rkvdec/rkvdec.h +++ b/drivers/staging/media/rkvdec/rkvdec.h @@ -75,13 +75,23 @@ struct rkvdec_coded_fmt_ops { int (*try_ctrl)(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl); }; =20 +enum rkvdec_image_fmt { + RKVDEC_IMG_FMT_ANY =3D 0, + RKVDEC_IMG_FMT_420_8BIT, +}; + +struct rkvdec_decoded_fmt_desc { + u32 fourcc; + enum rkvdec_image_fmt image_fmt; +}; + struct rkvdec_coded_fmt_desc { u32 fourcc; struct v4l2_frmsize_stepwise frmsize; const struct rkvdec_ctrls *ctrls; const struct rkvdec_coded_fmt_ops *ops; unsigned int num_decoded_fmts; - const u32 *decoded_fmts; + const struct rkvdec_decoded_fmt_desc *decoded_fmts; u32 subsystem_flags; }; =20 @@ -104,6 +114,7 @@ struct rkvdec_ctx { const struct rkvdec_coded_fmt_desc *coded_fmt_desc; struct v4l2_ctrl_handler ctrl_hdl; struct rkvdec_dev *dev; + enum rkvdec_image_fmt image_fmt; void *priv; }; =20 --=20 2.46.0