2023-01-12 13:20:39

by Sebastian Fricke

[permalink] [raw]
Subject: [PATCH v2 07/12] staging: media: rkvdec: Add a routine to fetch SPS attributes as a callback

Add a callback for each codec variant, that fetches basic information
like resolution, bit-depth and sub-sampling from a SPS structure. This
data is used to verify whether a new SPS structure is valid.

Signed-off-by: Sebastian Fricke <[email protected]>
---
drivers/staging/media/rkvdec/rkvdec.c | 10 ++++++++++
drivers/staging/media/rkvdec/rkvdec.h | 10 ++++++++++
2 files changed, 20 insertions(+)

diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
index a46f918926a2..e8c750a7343a 100644
--- a/drivers/staging/media/rkvdec/rkvdec.c
+++ b/drivers/staging/media/rkvdec/rkvdec.c
@@ -52,6 +52,16 @@ static int rkvdec_get_valid_fmt(struct rkvdec_ctx *ctx)
return ctx->coded_fmt_desc->decoded_fmts[0];
}

+static int rkvdec_get_sps_attributes(struct rkvdec_ctx *ctx, void *sps,
+ struct sps_attributes *attributes)
+{
+ const struct rkvdec_coded_fmt_desc *coded_desc = ctx->coded_fmt_desc;
+
+ if (coded_desc->ops->get_sps_attributes)
+ return coded_desc->ops->get_sps_attributes(ctx, sps, attributes);
+ return 0;
+}
+
static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
{
struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
diff --git a/drivers/staging/media/rkvdec/rkvdec.h b/drivers/staging/media/rkvdec/rkvdec.h
index e353a4403e5b..7b6702c360fd 100644
--- a/drivers/staging/media/rkvdec/rkvdec.h
+++ b/drivers/staging/media/rkvdec/rkvdec.h
@@ -63,10 +63,20 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)
base.vb.vb2_buf);
}

+struct sps_attributes {
+ unsigned int width;
+ unsigned int height;
+ unsigned int luma_bitdepth;
+ unsigned int chroma_bitdepth;
+ unsigned int subsampling;
+};
+
struct rkvdec_coded_fmt_ops {
int (*adjust_fmt)(struct rkvdec_ctx *ctx,
struct v4l2_format *f);
u32 (*valid_fmt)(struct rkvdec_ctx *ctx);
+ int (*get_sps_attributes)(struct rkvdec_ctx *ctx, void *sps,
+ struct sps_attributes *attributes);
int (*start)(struct rkvdec_ctx *ctx);
void (*stop)(struct rkvdec_ctx *ctx);
int (*run)(struct rkvdec_ctx *ctx);

--
2.25.1


2023-01-16 10:44:59

by Andrzej Pietrasiewicz

[permalink] [raw]
Subject: Re: [PATCH v2 07/12] staging: media: rkvdec: Add a routine to fetch SPS attributes as a callback

Hi Sebastian,

W dniu 12.01.2023 o 13:56, Sebastian Fricke pisze:
> Add a callback for each codec variant, that fetches basic information
> like resolution, bit-depth and sub-sampling from a SPS structure. This
> data is used to verify whether a new SPS structure is valid.
>
> Signed-off-by: Sebastian Fricke <[email protected]>
> ---
> drivers/staging/media/rkvdec/rkvdec.c | 10 ++++++++++
> drivers/staging/media/rkvdec/rkvdec.h | 10 ++++++++++
> 2 files changed, 20 insertions(+)
>
> diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> index a46f918926a2..e8c750a7343a 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.c
> +++ b/drivers/staging/media/rkvdec/rkvdec.c
> @@ -52,6 +52,16 @@ static int rkvdec_get_valid_fmt(struct rkvdec_ctx *ctx)
> return ctx->coded_fmt_desc->decoded_fmts[0];
> }
>
> +static int rkvdec_get_sps_attributes(struct rkvdec_ctx *ctx, void *sps,
> + struct sps_attributes *attributes)
> +{
> + const struct rkvdec_coded_fmt_desc *coded_desc = ctx->coded_fmt_desc;
> +
> + if (coded_desc->ops->get_sps_attributes)
> + return coded_desc->ops->get_sps_attributes(ctx, sps, attributes);
> + return 0;

It seems that if there's no ->get_sps_attributes(), then even though
"attributes" won't be filled in, the result is a success (as suggested
by the returned 0). That's maybe confusing to potential users, especially,
if they don't e.g. memset the attributes struct to zero - the function will
report "success" but the struct will contain random data.

In PATCH 09/12 you call the implementation directly (not through the ops
struct), and there you actually ignore the return value.

Regards,

Andrzej

> +}
> +
> static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
> {
> struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
> diff --git a/drivers/staging/media/rkvdec/rkvdec.h b/drivers/staging/media/rkvdec/rkvdec.h
> index e353a4403e5b..7b6702c360fd 100644
> --- a/drivers/staging/media/rkvdec/rkvdec.h
> +++ b/drivers/staging/media/rkvdec/rkvdec.h
> @@ -63,10 +63,20 @@ vb2_to_rkvdec_decoded_buf(struct vb2_buffer *buf)
> base.vb.vb2_buf);
> }
>
> +struct sps_attributes {
> + unsigned int width;
> + unsigned int height;
> + unsigned int luma_bitdepth;
> + unsigned int chroma_bitdepth;
> + unsigned int subsampling;
> +};
> +
> struct rkvdec_coded_fmt_ops {
> int (*adjust_fmt)(struct rkvdec_ctx *ctx,
> struct v4l2_format *f);
> u32 (*valid_fmt)(struct rkvdec_ctx *ctx);
> + int (*get_sps_attributes)(struct rkvdec_ctx *ctx, void *sps,
> + struct sps_attributes *attributes);
> int (*start)(struct rkvdec_ctx *ctx);
> void (*stop)(struct rkvdec_ctx *ctx);
> int (*run)(struct rkvdec_ctx *ctx);
>