public inbox for linux-media@vger.kernel.org
 help / color / mirror / Atom feed
From: Nicolas Dufresne <nicolas.dufresne@collabora.com>
To: Ezequiel Garcia <ezequiel@vanguardiasur.com.ar>,
	Sebastian Fricke <sebastian.fricke@collabora.com>
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-media@vger.kernel.org, linux-kernel@vger.kernel.org,
	linux-rockchip@lists.infradead.org,
	linux-staging@lists.linux.dev, Jonas Karlman <jonas@kwiboo.se>,
	Alex Bee <knaerzche@gmail.com>,
	Collabora Kernel-domain <kernel@collabora.com>,
	Robert Beckett <bob.beckett@collabora.com>,
	Laurent Pinchart <laurent.pinchart@ideasonboard.com>,
	Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
	Benjamin Gaignard <benjamin.gaignard@collabora.com>
Subject: Re: [PATCH v2 11/12] staging: media: rkvdec: Enable S_CTRL IOCTL
Date: Thu, 12 Jan 2023 17:04:48 -0500	[thread overview]
Message-ID: <6827059d3b3158bf2f8dfb2346a7e854d2a533a3.camel@collabora.com> (raw)
In-Reply-To: <CAAEAJfDm3FBUkacR+tRVYnEbO8g43RT_L89WQuZjRi-Kwn7CYA@mail.gmail.com>

Le jeudi 12 janvier 2023 à 12:09 -0300, Ezequiel Garcia a écrit :
> Hi Sebastian,
> 
> On Thu, Jan 12, 2023 at 9:57 AM Sebastian Fricke
> <sebastian.fricke@collabora.com> wrote:
> > 
> > Enable user-space to set the SPS of the current byte-stream on the
> > decoder. This action will enable the decoder to pick the optimal
> > pixel-format for the capture queue, whenever it is required.
> > 
> > Signed-off-by: Sebastian Fricke <sebastian.fricke@collabora.com>
> > Signed-off-by: Jonas Karlman <jonas@kwiboo.se>
> > ---
> >  drivers/staging/media/rkvdec/rkvdec.c | 81 +++++++++++++++++++++++++++++++++++
> >  1 file changed, 81 insertions(+)
> > 
> > diff --git a/drivers/staging/media/rkvdec/rkvdec.c b/drivers/staging/media/rkvdec/rkvdec.c
> > index b303c6e0286d..3d413c5ad1d2 100644
> > --- a/drivers/staging/media/rkvdec/rkvdec.c
> > +++ b/drivers/staging/media/rkvdec/rkvdec.c
> > @@ -93,6 +93,79 @@ static int rkvdec_get_sps_attributes(struct rkvdec_ctx *ctx, void *sps,
> >         return 0;
> >  }
> > 
> > +static int rkvdec_set_sps(struct rkvdec_ctx *ctx, struct v4l2_ctrl *ctrl)
> > +{
> > +       struct v4l2_pix_format_mplane *pix_mp;
> > +       struct sps_attributes attributes = {0};
> > +       void *new_sps = NULL;
> > +
> > +       /*
> > +        * SPS structures are not filled until the control handler is set up
> > +        */
> > +       if (!ctx->fh.ctrl_handler)
> > +               return 0;
> 
> The control handler is embedded in the context, and the fh.ctrl_handler
> is initialized when the context is returned.
> 
> You cannot have a context without a control handler (see hantro_open).
> 
> > +
> > +       switch (ctrl->id) {
> > +       case V4L2_CID_STATELESS_H264_SPS:
> > +               new_sps = (void *)ctrl->p_new.p_h264_sps;
> > +               break;
> > +       case V4L2_CID_STATELESS_HEVC_SPS:
> > +               new_sps = (void *)ctrl->p_new.p_hevc_sps;
> > +               break;
> > +       default:
> > +               dev_err(ctx->dev->dev, "Unsupported stateless control ID: %x\n", ctrl->id);
> > +               return -EINVAL;
> > +       };
> > +       rkvdec_get_sps_attributes(ctx, new_sps, &attributes);
> > +
> > +       /*
> > +        * Providing an empty SPS is valid but we do not store it.
> > +        */
> > +       if (attributes.width == 0 && attributes.height == 0)
> > +               return 0;
> > +
> > +       pix_mp = &ctx->decoded_fmt.fmt.pix_mp;
> > +
> > +       /*
> > +        * SPS must match the provided format dimension, if it doesn't userspace has to
> > +        * first reset the output format
> 
> This comment says it's a mismatch check, but the check is checking for
> "larger than".
> 
> Other than that, the general idea looks good, can you rework the series to avoid
> the extra storage of the SPS control in the context?

I'm not fan, but the careless alignment code states that the coded size cannot
be lower then 64x64, but while running the conformance, there is bunch of files
that have coded dimensions lower. And here's the reason why its not ==. I don't
really like this, but confusing allocation padding and coded size capability
seems to be deep down into rkvdec driver design.

If I only look at the FMT(OUTPUT) behaviour, anything < 64x64 is strictly not
supported by the driver, this the interpretation ffmpeg request code have, and
they are actually right. GStreamer simply does not check anything, and try
(there is not validation code there yet, and I don't want to add any until we
figure-out a solution).

> 
> Thanks,
> Ezequiel
> 
> > +        */
> > +       if ((attributes.width > pix_mp->width) || (attributes.height > pix_mp->height)) {
> > +               dev_err(ctx->dev->dev,
> > +                       "Dimension mismatch. [%s SPS] W: %d, H: %d, [Format] W: %d, H: %d)\n",
> > +                       ctrl->id == V4L2_CID_STATELESS_HEVC_SPS ? "HEVC" : "H264",
> > +                       attributes.width, attributes.height, pix_mp->width, pix_mp->height);
> > +               return -EINVAL;
> > +       }
> > +
> > +       if (ctx->sps && pix_mp->pixelformat == rkvdec_get_valid_fmt(ctx)) {
> > +               /*
> > +                * Userspace is allowed to change the SPS at any point, if the
> > +                * pixel format doesn't differ from the format in the context,
> > +                * just accept the change even if buffers are queued
> > +                */
> > +               ctx->sps = new_sps;
> > +       } else {
> > +               /*
> > +                * Do not accept changing the SPS, while buffers are queued,
> > +                * when the new SPS would cause switching the CAPTURE pixel format
> > +                */
> > +               if (pix_mp->pixelformat != rkvdec_get_valid_fmt(ctx)) {
> > +                       if (rkvdec_queue_busy(ctx, V4L2_BUF_TYPE_VIDEO_CAPTURE_MPLANE))
> > +                               return -EBUSY;
> > +               }
> > +               ctx->sps = new_sps;
> > +               /*
> > +                * For the initial SPS setting and when the pixel format is
> > +                * changed adjust the pixel format stored in the context
> > +                */
> > +               pix_mp->pixelformat = rkvdec_get_valid_fmt(ctx);
> > +               rkvdec_fill_decoded_pixfmt(ctx, pix_mp);
> > +       }
> > +
> > +       return 0;
> > +}
> > +
> >  static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
> >  {
> >         struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
> > @@ -104,8 +177,16 @@ static int rkvdec_try_ctrl(struct v4l2_ctrl *ctrl)
> >         return 0;
> >  }
> > 
> > +static int rkvdec_s_ctrl(struct v4l2_ctrl *ctrl)
> > +{
> > +       struct rkvdec_ctx *ctx = container_of(ctrl->handler, struct rkvdec_ctx, ctrl_hdl);
> > +
> > +       return rkvdec_set_sps(ctx, ctrl);
> > +}
> > +
> >  static const struct v4l2_ctrl_ops rkvdec_ctrl_ops = {
> >         .try_ctrl = rkvdec_try_ctrl,
> > +       .s_ctrl = rkvdec_s_ctrl,
> >  };
> > 
> >  static const struct rkvdec_ctrl_desc rkvdec_h264_ctrl_descs[] = {
> > 
> > --
> > 2.25.1


  reply	other threads:[~2023-01-12 22:12 UTC|newest]

Thread overview: 32+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-12 12:56 [PATCH v2 00/12] RkVDEC HEVC driver Sebastian Fricke
2023-01-12 12:56 ` [PATCH v2 01/12] media: v4l2: Add NV15 pixel format Sebastian Fricke
2023-01-13 12:19   ` kernel test robot
2023-02-16  8:57   ` Hsia-Jun Li
2023-02-16 17:00     ` Nicolas Dufresne
2023-02-17  2:40       ` Hsia-Jun Li
2023-01-12 12:56 ` [PATCH v2 02/12] media: v4l2-common: Add helpers to calculate bytesperline and sizeimage Sebastian Fricke
2023-01-12 12:56 ` [PATCH v2 03/12] staging: media: rkvdec: Helper for buffer queue busy check Sebastian Fricke
2023-01-16  7:54   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 04/12] staging: media: rkvdec: Block start streaming until both queues run Sebastian Fricke
2023-01-12 14:55   ` Ezequiel Garcia
2023-01-12 15:00     ` Dan Carpenter
2023-01-16  8:23   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 05/12] staging: media: rkvdec: Add SPS structure to internal context Sebastian Fricke
2023-01-12 15:02   ` Ezequiel Garcia
2023-01-16 10:00     ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 06/12] staging: media: rkvdec: Add a valid pixel format check as callback Sebastian Fricke
2023-01-12 15:30   ` Ezequiel Garcia
2023-01-12 12:56 ` [PATCH v2 07/12] staging: media: rkvdec: Add a routine to fetch SPS attributes as a callback Sebastian Fricke
2023-01-16 10:27   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 08/12] staging: media: rkvdec: Add a valid SPS check " Sebastian Fricke
2023-01-12 12:56 ` [PATCH v2 09/12] staging: media: rkvdec: h264: Add callbacks for h264 Sebastian Fricke
2023-01-12 15:21   ` Ezequiel Garcia
2023-01-12 21:58     ` Nicolas Dufresne
2023-01-12 12:56 ` [PATCH v2 10/12] staging: media: rkvdec: Wrapper for pixel format preparation Sebastian Fricke
2023-01-16 10:42   ` Andrzej Pietrasiewicz
2023-01-12 12:56 ` [PATCH v2 11/12] staging: media: rkvdec: Enable S_CTRL IOCTL Sebastian Fricke
2023-01-12 15:09   ` Ezequiel Garcia
2023-01-12 22:04     ` Nicolas Dufresne [this message]
2023-01-12 12:56 ` [PATCH v2 12/12] staging: media: rkvdec: Add HEVC backend Sebastian Fricke
2023-01-12 18:27   ` kernel test robot
2023-01-16 12:44   ` Andrzej Pietrasiewicz

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=6827059d3b3158bf2f8dfb2346a7e854d2a533a3.camel@collabora.com \
    --to=nicolas.dufresne@collabora.com \
    --cc=andrzej.p@collabora.com \
    --cc=benjamin.gaignard@collabora.com \
    --cc=bob.beckett@collabora.com \
    --cc=ezequiel@vanguardiasur.com.ar \
    --cc=gregkh@linuxfoundation.org \
    --cc=jonas@kwiboo.se \
    --cc=kernel@collabora.com \
    --cc=knaerzche@gmail.com \
    --cc=laurent.pinchart@ideasonboard.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=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