linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v3] media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at eos
@ 2022-02-22  8:41 Ming Qian
  2022-02-22  8:48 ` Hans Verkuil
  0 siblings, 1 reply; 3+ messages in thread
From: Ming Qian @ 2022-02-22  8:41 UTC (permalink / raw)
  To: mchehab, shawnguo, s.hauer, mirela.rabulea
  Cc: hverkuil-cisco, kernel, festevam, linux-imx, linux-media,
	linux-kernel, devicetree, linux-arm-kernel

The V4L2_EVENT_EOS event is a deprecated behavior,
the V4L2_BUF_FLAG_LAST buffer flag should be used instead.

Signed-off-by: Ming Qian <ming.qian@nxp.com>
Reviewed-by: Mirela Rabulea <mirela.rabulea@nxp.com>
---
 drivers/media/platform/imx-jpeg/mxc-jpeg.c | 41 ++++++++++++++++++++--
 drivers/media/platform/imx-jpeg/mxc-jpeg.h |  1 +
 2 files changed, 40 insertions(+), 2 deletions(-)

diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
index ec5a326affd6..1de0400750aa 100644
--- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c
+++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
@@ -997,6 +997,20 @@ static void mxc_jpeg_device_run(void *priv)
 	spin_unlock_irqrestore(&ctx->mxc_jpeg->hw_lock, flags);
 }
 
+static void mxc_jpeg_set_last_buffer_dequeued(struct mxc_jpeg_ctx *ctx)
+{
+	struct vb2_queue *q;
+
+	ctx->stopped = 1;
+	q = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx);
+	if (!list_empty(&q->done_list))
+		return;
+
+	q->last_buffer_dequeued = true;
+	wake_up(&q->done_wq);
+	ctx->stopped = 0;
+}
+
 static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
 				struct v4l2_decoder_cmd *cmd)
 {
@@ -1014,6 +1028,7 @@ static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
 		if (v4l2_m2m_num_src_bufs_ready(fh->m2m_ctx) == 0) {
 			/* No more src bufs, notify app EOS */
 			notify_eos(ctx);
+			mxc_jpeg_set_last_buffer_dequeued(ctx);
 		} else {
 			/* will send EOS later*/
 			ctx->stopping = 1;
@@ -1040,6 +1055,7 @@ static int mxc_jpeg_encoder_cmd(struct file *file, void *priv,
 		if (v4l2_m2m_num_src_bufs_ready(fh->m2m_ctx) == 0) {
 			/* No more src bufs, notify app EOS */
 			notify_eos(ctx);
+			mxc_jpeg_set_last_buffer_dequeued(ctx);
 		} else {
 			/* will send EOS later*/
 			ctx->stopping = 1;
@@ -1116,6 +1132,10 @@ static void mxc_jpeg_stop_streaming(struct vb2_queue *q)
 		v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
 	}
 	pm_runtime_put_sync(&ctx->mxc_jpeg->pdev->dev);
+	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
+		ctx->stopping = 0;
+		ctx->stopped = 0;
+	}
 }
 
 static int mxc_jpeg_valid_comp_id(struct device *dev,
@@ -1407,12 +1427,29 @@ static int mxc_jpeg_buf_prepare(struct vb2_buffer *vb)
 	return 0;
 }
 
+static void mxc_jpeg_buf_finish(struct vb2_buffer *vb)
+{
+	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
+	struct mxc_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
+	struct vb2_queue *q = vb->vb2_queue;
+
+	if (V4L2_TYPE_IS_OUTPUT(vb->type))
+		return;
+	if (!ctx->stopped)
+		return;
+	if (list_empty(&q->done_list)) {
+		vbuf->flags |= V4L2_BUF_FLAG_LAST;
+		ctx->stopped = 0;
+	}
+}
+
 static const struct vb2_ops mxc_jpeg_qops = {
 	.queue_setup		= mxc_jpeg_queue_setup,
 	.wait_prepare		= vb2_ops_wait_prepare,
 	.wait_finish		= vb2_ops_wait_finish,
 	.buf_out_validate	= mxc_jpeg_buf_out_validate,
 	.buf_prepare		= mxc_jpeg_buf_prepare,
+	.buf_finish             = mxc_jpeg_buf_finish,
 	.start_streaming	= mxc_jpeg_start_streaming,
 	.stop_streaming		= mxc_jpeg_stop_streaming,
 	.buf_queue		= mxc_jpeg_buf_queue,
@@ -1848,14 +1885,14 @@ static int mxc_jpeg_dqbuf(struct file *file, void *priv,
 	int ret;
 
 	dev_dbg(dev, "DQBUF type=%d, index=%d", buf->type, buf->index);
-	if (ctx->stopping == 1	&& num_src_ready == 0) {
+	if (ctx->stopping == 1 && num_src_ready == 0) {
 		/* No more src bufs, notify app EOS */
 		notify_eos(ctx);
 		ctx->stopping = 0;
+		mxc_jpeg_set_last_buffer_dequeued(ctx);
 	}
 
 	ret = v4l2_m2m_dqbuf(file, fh->m2m_ctx, buf);
-
 	return ret;
 }
 
diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/imx-jpeg/mxc-jpeg.h
index 9fb2a5aaa941..f53f004ba851 100644
--- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h
+++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.h
@@ -91,6 +91,7 @@ struct mxc_jpeg_ctx {
 	struct v4l2_fh			fh;
 	enum mxc_jpeg_enc_state		enc_state;
 	unsigned int			stopping;
+	unsigned int			stopped;
 	unsigned int			slot;
 };
 
-- 
2.33.0


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH v3] media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at eos
  2022-02-22  8:41 [PATCH v3] media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at eos Ming Qian
@ 2022-02-22  8:48 ` Hans Verkuil
  2022-02-22  9:02   ` [EXT] " Ming Qian
  0 siblings, 1 reply; 3+ messages in thread
From: Hans Verkuil @ 2022-02-22  8:48 UTC (permalink / raw)
  To: Ming Qian, mchehab, shawnguo, s.hauer, mirela.rabulea
  Cc: kernel, festevam, linux-imx, linux-media, linux-kernel,
	devicetree, linux-arm-kernel

What changed in v3?

The v2 is already part of a PR, so if the changes are just of the cleanup
type, then I prefer to have a diff on top of the v2. Otherwise I need to
respin the PR.

Regards,

	Hans

On 2/22/22 09:41, Ming Qian wrote:
> The V4L2_EVENT_EOS event is a deprecated behavior,
> the V4L2_BUF_FLAG_LAST buffer flag should be used instead.
> 
> Signed-off-by: Ming Qian <ming.qian@nxp.com>
> Reviewed-by: Mirela Rabulea <mirela.rabulea@nxp.com>
> ---
>  drivers/media/platform/imx-jpeg/mxc-jpeg.c | 41 ++++++++++++++++++++--
>  drivers/media/platform/imx-jpeg/mxc-jpeg.h |  1 +
>  2 files changed, 40 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> index ec5a326affd6..1de0400750aa 100644
> --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> @@ -997,6 +997,20 @@ static void mxc_jpeg_device_run(void *priv)
>  	spin_unlock_irqrestore(&ctx->mxc_jpeg->hw_lock, flags);
>  }
>  
> +static void mxc_jpeg_set_last_buffer_dequeued(struct mxc_jpeg_ctx *ctx)
> +{
> +	struct vb2_queue *q;
> +
> +	ctx->stopped = 1;
> +	q = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx);
> +	if (!list_empty(&q->done_list))
> +		return;
> +
> +	q->last_buffer_dequeued = true;
> +	wake_up(&q->done_wq);
> +	ctx->stopped = 0;
> +}
> +
>  static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
>  				struct v4l2_decoder_cmd *cmd)
>  {
> @@ -1014,6 +1028,7 @@ static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
>  		if (v4l2_m2m_num_src_bufs_ready(fh->m2m_ctx) == 0) {
>  			/* No more src bufs, notify app EOS */
>  			notify_eos(ctx);
> +			mxc_jpeg_set_last_buffer_dequeued(ctx);
>  		} else {
>  			/* will send EOS later*/
>  			ctx->stopping = 1;
> @@ -1040,6 +1055,7 @@ static int mxc_jpeg_encoder_cmd(struct file *file, void *priv,
>  		if (v4l2_m2m_num_src_bufs_ready(fh->m2m_ctx) == 0) {
>  			/* No more src bufs, notify app EOS */
>  			notify_eos(ctx);
> +			mxc_jpeg_set_last_buffer_dequeued(ctx);
>  		} else {
>  			/* will send EOS later*/
>  			ctx->stopping = 1;
> @@ -1116,6 +1132,10 @@ static void mxc_jpeg_stop_streaming(struct vb2_queue *q)
>  		v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
>  	}
>  	pm_runtime_put_sync(&ctx->mxc_jpeg->pdev->dev);
> +	if (V4L2_TYPE_IS_OUTPUT(q->type)) {
> +		ctx->stopping = 0;
> +		ctx->stopped = 0;
> +	}
>  }
>  
>  static int mxc_jpeg_valid_comp_id(struct device *dev,
> @@ -1407,12 +1427,29 @@ static int mxc_jpeg_buf_prepare(struct vb2_buffer *vb)
>  	return 0;
>  }
>  
> +static void mxc_jpeg_buf_finish(struct vb2_buffer *vb)
> +{
> +	struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> +	struct mxc_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
> +	struct vb2_queue *q = vb->vb2_queue;
> +
> +	if (V4L2_TYPE_IS_OUTPUT(vb->type))
> +		return;
> +	if (!ctx->stopped)
> +		return;
> +	if (list_empty(&q->done_list)) {
> +		vbuf->flags |= V4L2_BUF_FLAG_LAST;
> +		ctx->stopped = 0;
> +	}
> +}
> +
>  static const struct vb2_ops mxc_jpeg_qops = {
>  	.queue_setup		= mxc_jpeg_queue_setup,
>  	.wait_prepare		= vb2_ops_wait_prepare,
>  	.wait_finish		= vb2_ops_wait_finish,
>  	.buf_out_validate	= mxc_jpeg_buf_out_validate,
>  	.buf_prepare		= mxc_jpeg_buf_prepare,
> +	.buf_finish             = mxc_jpeg_buf_finish,
>  	.start_streaming	= mxc_jpeg_start_streaming,
>  	.stop_streaming		= mxc_jpeg_stop_streaming,
>  	.buf_queue		= mxc_jpeg_buf_queue,
> @@ -1848,14 +1885,14 @@ static int mxc_jpeg_dqbuf(struct file *file, void *priv,
>  	int ret;
>  
>  	dev_dbg(dev, "DQBUF type=%d, index=%d", buf->type, buf->index);
> -	if (ctx->stopping == 1	&& num_src_ready == 0) {
> +	if (ctx->stopping == 1 && num_src_ready == 0) {
>  		/* No more src bufs, notify app EOS */
>  		notify_eos(ctx);
>  		ctx->stopping = 0;
> +		mxc_jpeg_set_last_buffer_dequeued(ctx);
>  	}
>  
>  	ret = v4l2_m2m_dqbuf(file, fh->m2m_ctx, buf);
> -
>  	return ret;
>  }
>  
> diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.h b/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> index 9fb2a5aaa941..f53f004ba851 100644
> --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> @@ -91,6 +91,7 @@ struct mxc_jpeg_ctx {
>  	struct v4l2_fh			fh;
>  	enum mxc_jpeg_enc_state		enc_state;
>  	unsigned int			stopping;
> +	unsigned int			stopped;
>  	unsigned int			slot;
>  };
>  

_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

* RE: [EXT] Re: [PATCH v3] media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at eos
  2022-02-22  8:48 ` Hans Verkuil
@ 2022-02-22  9:02   ` Ming Qian
  0 siblings, 0 replies; 3+ messages in thread
From: Ming Qian @ 2022-02-22  9:02 UTC (permalink / raw)
  To: Hans Verkuil, mchehab, shawnguo, s.hauer, Mirela Rabulea (OSS)
  Cc: kernel, festevam, dl-linux-imx, linux-media, linux-kernel,
	devicetree, linux-arm-kernel

> -----Original Message-----
> From: Hans Verkuil [mailto:hverkuil-cisco@xs4all.nl]
> Sent: Tuesday, February 22, 2022 4:49 PM
> To: Ming Qian <ming.qian@nxp.com>; mchehab@kernel.org;
> shawnguo@kernel.org; s.hauer@pengutronix.de; Mirela Rabulea (OSS)
> <mirela.rabulea@oss.nxp.com>
> Cc: kernel@pengutronix.de; festevam@gmail.com; dl-linux-imx
> <linux-imx@nxp.com>; linux-media@vger.kernel.org;
> linux-kernel@vger.kernel.org; devicetree@vger.kernel.org;
> linux-arm-kernel@lists.infradead.org
> Subject: [EXT] Re: [PATCH v3] media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at
> eos
> 
> Caution: EXT Email
> 
> What changed in v3?

In v2, I just clear the stopping flag in stop_streaming callback.
But I think it should be cleared only when calling streamoff on output queue,
as the streamoff of capture queue may be called in source change. 
So I make the change:
if (V4L2_TYPE_IS_OUTPUT(q->type)) {
	ctx->stopping = 0;
	ctx->stopped = 0;
}

> 
> The v2 is already part of a PR, so if the changes are just of the cleanup type,
> then I prefer to have a diff on top of the v2. Otherwise I need to respin the PR.
> 
> Regards,
> 
>         Hans
> 
> On 2/22/22 09:41, Ming Qian wrote:
> > The V4L2_EVENT_EOS event is a deprecated behavior, the
> > V4L2_BUF_FLAG_LAST buffer flag should be used instead.
> >
> > Signed-off-by: Ming Qian <ming.qian@nxp.com>
> > Reviewed-by: Mirela Rabulea <mirela.rabulea@nxp.com>
> > ---
> >  drivers/media/platform/imx-jpeg/mxc-jpeg.c | 41
> > ++++++++++++++++++++--  drivers/media/platform/imx-jpeg/mxc-jpeg.h |
> > 1 +
> >  2 files changed, 40 insertions(+), 2 deletions(-)
> >
> > diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> > b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> > index ec5a326affd6..1de0400750aa 100644
> > --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> > +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.c
> > @@ -997,6 +997,20 @@ static void mxc_jpeg_device_run(void *priv)
> >       spin_unlock_irqrestore(&ctx->mxc_jpeg->hw_lock, flags);  }
> >
> > +static void mxc_jpeg_set_last_buffer_dequeued(struct mxc_jpeg_ctx
> > +*ctx) {
> > +     struct vb2_queue *q;
> > +
> > +     ctx->stopped = 1;
> > +     q = v4l2_m2m_get_dst_vq(ctx->fh.m2m_ctx);
> > +     if (!list_empty(&q->done_list))
> > +             return;
> > +
> > +     q->last_buffer_dequeued = true;
> > +     wake_up(&q->done_wq);
> > +     ctx->stopped = 0;
> > +}
> > +
> >  static int mxc_jpeg_decoder_cmd(struct file *file, void *priv,
> >                               struct v4l2_decoder_cmd *cmd)  { @@
> > -1014,6 +1028,7 @@ static int mxc_jpeg_decoder_cmd(struct file *file, void
> *priv,
> >               if (v4l2_m2m_num_src_bufs_ready(fh->m2m_ctx) == 0) {
> >                       /* No more src bufs, notify app EOS */
> >                       notify_eos(ctx);
> > +                     mxc_jpeg_set_last_buffer_dequeued(ctx);
> >               } else {
> >                       /* will send EOS later*/
> >                       ctx->stopping = 1; @@ -1040,6 +1055,7 @@
> static
> > int mxc_jpeg_encoder_cmd(struct file *file, void *priv,
> >               if (v4l2_m2m_num_src_bufs_ready(fh->m2m_ctx) == 0) {
> >                       /* No more src bufs, notify app EOS */
> >                       notify_eos(ctx);
> > +                     mxc_jpeg_set_last_buffer_dequeued(ctx);
> >               } else {
> >                       /* will send EOS later*/
> >                       ctx->stopping = 1; @@ -1116,6 +1132,10 @@
> static
> > void mxc_jpeg_stop_streaming(struct vb2_queue *q)
> >               v4l2_m2m_buf_done(vbuf, VB2_BUF_STATE_ERROR);
> >       }
> >       pm_runtime_put_sync(&ctx->mxc_jpeg->pdev->dev);
> > +     if (V4L2_TYPE_IS_OUTPUT(q->type)) {
> > +             ctx->stopping = 0;
> > +             ctx->stopped = 0;
> > +     }
> >  }
> >
> >  static int mxc_jpeg_valid_comp_id(struct device *dev, @@ -1407,12
> > +1427,29 @@ static int mxc_jpeg_buf_prepare(struct vb2_buffer *vb)
> >       return 0;
> >  }
> >
> > +static void mxc_jpeg_buf_finish(struct vb2_buffer *vb) {
> > +     struct vb2_v4l2_buffer *vbuf = to_vb2_v4l2_buffer(vb);
> > +     struct mxc_jpeg_ctx *ctx = vb2_get_drv_priv(vb->vb2_queue);
> > +     struct vb2_queue *q = vb->vb2_queue;
> > +
> > +     if (V4L2_TYPE_IS_OUTPUT(vb->type))
> > +             return;
> > +     if (!ctx->stopped)
> > +             return;
> > +     if (list_empty(&q->done_list)) {
> > +             vbuf->flags |= V4L2_BUF_FLAG_LAST;
> > +             ctx->stopped = 0;
> > +     }
> > +}
> > +
> >  static const struct vb2_ops mxc_jpeg_qops = {
> >       .queue_setup            = mxc_jpeg_queue_setup,
> >       .wait_prepare           = vb2_ops_wait_prepare,
> >       .wait_finish            = vb2_ops_wait_finish,
> >       .buf_out_validate       = mxc_jpeg_buf_out_validate,
> >       .buf_prepare            = mxc_jpeg_buf_prepare,
> > +     .buf_finish             = mxc_jpeg_buf_finish,
> >       .start_streaming        = mxc_jpeg_start_streaming,
> >       .stop_streaming         = mxc_jpeg_stop_streaming,
> >       .buf_queue              = mxc_jpeg_buf_queue,
> > @@ -1848,14 +1885,14 @@ static int mxc_jpeg_dqbuf(struct file *file, void
> *priv,
> >       int ret;
> >
> >       dev_dbg(dev, "DQBUF type=%d, index=%d", buf->type, buf->index);
> > -     if (ctx->stopping == 1  && num_src_ready == 0) {
> > +     if (ctx->stopping == 1 && num_src_ready == 0) {
> >               /* No more src bufs, notify app EOS */
> >               notify_eos(ctx);
> >               ctx->stopping = 0;
> > +             mxc_jpeg_set_last_buffer_dequeued(ctx);
> >       }
> >
> >       ret = v4l2_m2m_dqbuf(file, fh->m2m_ctx, buf);
> > -
> >       return ret;
> >  }
> >
> > diff --git a/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> > b/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> > index 9fb2a5aaa941..f53f004ba851 100644
> > --- a/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> > +++ b/drivers/media/platform/imx-jpeg/mxc-jpeg.h
> > @@ -91,6 +91,7 @@ struct mxc_jpeg_ctx {
> >       struct v4l2_fh                  fh;
> >       enum mxc_jpeg_enc_state         enc_state;
> >       unsigned int                    stopping;
> > +     unsigned int                    stopped;
> >       unsigned int                    slot;
> >  };
> >
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2022-02-22  9:04 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-02-22  8:41 [PATCH v3] media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at eos Ming Qian
2022-02-22  8:48 ` Hans Verkuil
2022-02-22  9:02   ` [EXT] " Ming Qian

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).