From: Jonas Karlman <jonas@kwiboo.se>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
Mauro Carvalho Chehab <mchehab@kernel.org>,
Hans Verkuil <hverkuil-cisco@xs4all.nl>,
"Greg Kroah-Hartman" <gregkh@linuxfoundation.org>
Cc: Alex Bee <knaerzche@gmail.com>,
Nicolas Dufresne <nicolas.dufresne@collabora.com>,
Benjamin Gaignard <benjamin.gaignard@collabora.com>,
Sebastian Fricke <sebastian.fricke@collabora.com>,
Christopher Obbard <chris.obbard@collabora.com>,
Detlev Casanova <detlev.casanova@collabora.com>,
linux-media@vger.kernel.org, linux-rockchip@lists.infradead.org,
linux-staging@lists.linux.dev, linux-kernel@vger.kernel.org,
Jonas Karlman <jonas@kwiboo.se>
Subject: [PATCH v5 08/10] media: rkvdec: Add image format concept
Date: Tue, 18 Jun 2024 19:46:32 +0000 [thread overview]
Message-ID: <20240618194647.742037-9-jonas@kwiboo.se> (raw)
In-Reply-To: <20240618194647.742037-1-jonas@kwiboo.se>
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 <jonas@kwiboo.se>
Tested-by: Nicolas Dufresne <nicolas.dufresne@collabora.com>
Tested-by: Christopher Obbard <chris.obbard@collabora.com>
---
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 | 45 ++++++++++++++++++++-------
drivers/staging/media/rkvdec/rkvdec.h | 13 +++++++-
2 files changed, 45 insertions(+), 13 deletions(-)
diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index efbf9aa578ae..d8fb2d935ffc 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -27,26 +27,42 @@
#include "rkvdec.h"
#include "rkvdec-regs.h"
-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 == fmt2 || fmt2 == RKVDEC_IMG_FMT_ANY ||
+ fmt1 == 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 = ctx->coded_fmt_desc;
+ unsigned int i, j;
if (WARN_ON(!desc))
return 0;
- if (index >= desc->num_decoded_fmts)
- return 0;
+ for (i = 0, j = 0; i < desc->num_decoded_fmts; i++) {
+ if (rkvdec_image_fmt_match(desc->decoded_fmts[i].image_fmt,
+ image_fmt) &&
+ index == j++)
+ return desc->decoded_fmts[i].fourcc;
+ }
- return desc->decoded_fmts[index];
+ return 0;
}
-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 = ctx->coded_fmt_desc;
unsigned int i;
for (i = 0; i < desc->num_decoded_fmts; i++) {
- if (desc->decoded_fmts[i] == fourcc)
+ if (rkvdec_image_fmt_match(desc->decoded_fmts[i].image_fmt,
+ image_fmt) &&
+ desc->decoded_fmts[i].fourcc == fourcc)
return true;
}
@@ -80,7 +96,7 @@ static void rkvdec_reset_decoded_fmt(struct rkvdec_ctx *ctx)
struct v4l2_format *f = &ctx->decoded_fmt;
u32 fourcc;
- fourcc = rkvdec_enum_decoded_fmt(ctx, 0);
+ fourcc = rkvdec_enum_decoded_fmt(ctx, 0, ctx->image_fmt);
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;
@@ -149,8 +165,11 @@ static const struct rkvdec_ctrls rkvdec_h264_ctrls = {
.num_ctrls = ARRAY_SIZE(rkvdec_h264_ctrl_descs),
};
-static const u32 rkvdec_h264_vp9_decoded_fmts[] = {
- V4L2_PIX_FMT_NV12,
+static const struct rkvdec_decoded_fmt_desc rkvdec_h264_vp9_decoded_fmts[] = {
+ {
+ .fourcc = V4L2_PIX_FMT_NV12,
+ .image_fmt = RKVDEC_IMG_FMT_420_8BIT,
+ },
};
static const struct rkvdec_ctrl_desc rkvdec_vp9_ctrl_descs[] = {
@@ -282,8 +301,9 @@ static int rkvdec_try_capture_fmt(struct file *file, void *priv,
if (WARN_ON(!coded_desc))
return -EINVAL;
- if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat))
- pix_mp->pixelformat = rkvdec_enum_decoded_fmt(ctx, 0);
+ if (!rkvdec_is_valid_fmt(ctx, pix_mp->pixelformat, ctx->image_fmt))
+ pix_mp->pixelformat = rkvdec_enum_decoded_fmt(ctx, 0,
+ ctx->image_fmt);
/* Always apply the frmsize constraint of the coded end. */
pix_mp->width = max(pix_mp->width, ctx->coded_fmt.fmt.pix_mp.width);
@@ -400,6 +420,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 = RKVDEC_IMG_FMT_ANY;
rkvdec_reset_decoded_fmt(ctx);
/* Propagate colorspace information to capture. */
@@ -449,7 +470,7 @@ static int rkvdec_enum_capture_fmt(struct file *file, void *priv,
struct rkvdec_ctx *ctx = fh_to_rkvdec_ctx(priv);
u32 fourcc;
- fourcc = rkvdec_enum_decoded_fmt(ctx, f->index);
+ fourcc = rkvdec_enum_decoded_fmt(ctx, f->index, ctx->image_fmt);
if (!fourcc)
return -EINVAL;
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);
};
+enum rkvdec_image_fmt {
+ RKVDEC_IMG_FMT_ANY = 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;
};
@@ -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;
};
--
2.45.2
next prev parent reply other threads:[~2024-06-18 19:47 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-06-18 19:46 [PATCH v5 00/10] media: rkvdec: Add H.264 High 10 and 4:2:2 profile support Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 01/10] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 02/10] media: v4l2: Add NV15 and NV20 pixel formats Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 03/10] media: rkvdec: h264: Use bytesperline and buffer height as virstride Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 04/10] media: rkvdec: h264: Don't hardcode SPS/PPS parameters Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 05/10] media: rkvdec: Extract rkvdec_fill_decoded_pixfmt into helper Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 06/10] media: rkvdec: Move rkvdec_reset_decoded_fmt helper Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 07/10] media: rkvdec: Extract decoded format enumeration into helper Jonas Karlman
2024-06-18 19:46 ` Jonas Karlman [this message]
2024-06-19 7:21 ` [PATCH v5 08/10] media: rkvdec: Add image format concept Dan Carpenter
2024-06-27 9:39 ` Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 09/10] media: rkvdec: Add get_image_fmt ops Jonas Karlman
2024-06-18 19:46 ` [PATCH v5 10/10] media: rkvdec: h264: Support High 10 and 4:2:2 profiles Jonas Karlman
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=20240618194647.742037-9-jonas@kwiboo.se \
--to=jonas@kwiboo.se \
--cc=benjamin.gaignard@collabora.com \
--cc=chris.obbard@collabora.com \
--cc=detlev.casanova@collabora.com \
--cc=ezequiel@vanguardiasur.com.ar \
--cc=gregkh@linuxfoundation.org \
--cc=hverkuil-cisco@xs4all.nl \
--cc=knaerzche@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-media@vger.kernel.org \
--cc=linux-rockchip@lists.infradead.org \
--cc=linux-staging@lists.linux.dev \
--cc=mchehab@kernel.org \
--cc=nicolas.dufresne@collabora.com \
--cc=sebastian.fricke@collabora.com \
/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
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®