Skip to content

Commit

Permalink
media: imx-jpeg: Set V4L2_BUF_FLAG_LAST at eos
Browse files Browse the repository at this point in the history
[ Upstream commit d8ebe29 ]

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>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Sasha Levin <sashal@kernel.org>
  • Loading branch information
mingqian-0 authored and gregkh committed Aug 17, 2022
1 parent 5709766 commit cab2a15
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 2 deletions.
41 changes: 39 additions & 2 deletions drivers/media/platform/imx-jpeg/mxc-jpeg.c
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,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)
{
Expand All @@ -1005,6 +1019,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;
Expand All @@ -1031,6 +1046,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;
Expand Down Expand Up @@ -1107,6 +1123,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,
Expand Down Expand Up @@ -1398,12 +1418,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,
Expand Down Expand Up @@ -1839,14 +1876,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;
}

Expand Down
1 change: 1 addition & 0 deletions drivers/media/platform/imx-jpeg/mxc-jpeg.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
};

Expand Down

0 comments on commit cab2a15

Please sign in to comment.