linux-media.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: linux-media@vger.kernel.org
Cc: Mauro Carvalho Chehab <mchehab@kernel.org>,
	Hans Verkuil <hverkuil@xs4all.nl>,
	kernel@pengutronix.de
Subject: [PATCH 08/28] media: coda: add sequence initialization work
Date: Tue, 18 Jun 2019 18:45:15 +0200	[thread overview]
Message-ID: <20190618164535.20162-9-p.zabel@pengutronix.de> (raw)
In-Reply-To: <20190618164535.20162-1-p.zabel@pengutronix.de>

Add a sequence initialization work item to be run when OUTPUT buffers
are queued in the initialization state.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda/coda-bit.c    | 25 +++++++++++++++++++++++
 drivers/media/platform/coda/coda-common.c | 24 ++++++++++++++++++++++
 drivers/media/platform/coda/coda.h        |  2 ++
 3 files changed, 51 insertions(+)

diff --git a/drivers/media/platform/coda/coda-bit.c b/drivers/media/platform/coda/coda-bit.c
index cecfd51e3838..9f8e2342d175 100644
--- a/drivers/media/platform/coda/coda-bit.c
+++ b/drivers/media/platform/coda/coda-bit.c
@@ -1824,6 +1824,30 @@ static int __coda_decoder_seq_init(struct coda_ctx *ctx)
 	return 0;
 }
 
+static void coda_dec_seq_init_work(struct work_struct *work)
+{
+	struct coda_ctx *ctx = container_of(work,
+					    struct coda_ctx, seq_init_work);
+	struct coda_dev *dev = ctx->dev;
+	int ret;
+
+	mutex_lock(&ctx->buffer_mutex);
+	mutex_lock(&dev->coda_mutex);
+
+	if (ctx->initialized == 1)
+		goto out;
+
+	ret = __coda_decoder_seq_init(ctx);
+	if (ret < 0)
+		goto out;
+
+	ctx->initialized = 1;
+
+out:
+	mutex_unlock(&dev->coda_mutex);
+	mutex_unlock(&ctx->buffer_mutex);
+}
+
 static int __coda_start_decoding(struct coda_ctx *ctx)
 {
 	struct coda_q_data *q_data_src, *q_data_dst;
@@ -2352,6 +2376,7 @@ const struct coda_context_ops coda_bit_decode_ops = {
 	.prepare_run = coda_prepare_decode,
 	.finish_run = coda_finish_decode,
 	.run_timeout = coda_decode_timeout,
+	.seq_init_work = coda_dec_seq_init_work,
 	.seq_end_work = coda_seq_end_work,
 	.release = coda_bit_release,
 };
diff --git a/drivers/media/platform/coda/coda-common.c b/drivers/media/platform/coda/coda-common.c
index 232bda4b7016..f8cfafa2ce42 100644
--- a/drivers/media/platform/coda/coda-common.c
+++ b/drivers/media/platform/coda/coda-common.c
@@ -1684,6 +1684,19 @@ static void coda_buf_queue(struct vb2_buffer *vb)
 			/* This set buf->sequence = ctx->qsequence++ */
 			coda_fill_bitstream(ctx, NULL);
 		mutex_unlock(&ctx->bitstream_mutex);
+
+		if (!ctx->initialized) {
+			/*
+			 * Run sequence initialization in case the queued
+			 * buffer contained headers.
+			 */
+			if (vb2_is_streaming(vb->vb2_queue) &&
+			    ctx->ops->seq_init_work) {
+				queue_work(ctx->dev->workqueue,
+					   &ctx->seq_init_work);
+				flush_work(&ctx->seq_init_work);
+			}
+		}
 	} else {
 		if (ctx->inst_type == CODA_INST_ENCODER &&
 		    vq->type == V4L2_BUF_TYPE_VIDEO_OUTPUT)
@@ -1761,6 +1774,15 @@ static int coda_start_streaming(struct vb2_queue *q, unsigned int count)
 				ret = -EINVAL;
 				goto err;
 			}
+
+			if (!ctx->initialized) {
+				/* Run sequence initialization */
+				if (ctx->ops->seq_init_work) {
+					queue_work(ctx->dev->workqueue,
+						   &ctx->seq_init_work);
+					flush_work(&ctx->seq_init_work);
+				}
+			}
 		}
 
 		ctx->streamon_out = 1;
@@ -2317,6 +2339,8 @@ static int coda_open(struct file *file)
 	ctx->use_bit = !ctx->cvd->direct;
 	init_completion(&ctx->completion);
 	INIT_WORK(&ctx->pic_run_work, coda_pic_run_work);
+	if (ctx->ops->seq_init_work)
+		INIT_WORK(&ctx->seq_init_work, ctx->ops->seq_init_work);
 	if (ctx->ops->seq_end_work)
 		INIT_WORK(&ctx->seq_end_work, ctx->ops->seq_end_work);
 	v4l2_fh_init(&ctx->fh, video_devdata(file));
diff --git a/drivers/media/platform/coda/coda.h b/drivers/media/platform/coda/coda.h
index 0c2cace53ce8..c97ea3e24b80 100644
--- a/drivers/media/platform/coda/coda.h
+++ b/drivers/media/platform/coda/coda.h
@@ -185,6 +185,7 @@ struct coda_context_ops {
 	int (*prepare_run)(struct coda_ctx *ctx);
 	void (*finish_run)(struct coda_ctx *ctx);
 	void (*run_timeout)(struct coda_ctx *ctx);
+	void (*seq_init_work)(struct work_struct *work);
 	void (*seq_end_work)(struct work_struct *work);
 	void (*release)(struct coda_ctx *ctx);
 };
@@ -193,6 +194,7 @@ struct coda_ctx {
 	struct coda_dev			*dev;
 	struct mutex			buffer_mutex;
 	struct work_struct		pic_run_work;
+	struct work_struct		seq_init_work;
 	struct work_struct		seq_end_work;
 	struct completion		completion;
 	const struct coda_video_device	*cvd;
-- 
2.20.1


  parent reply	other threads:[~2019-06-18 16:46 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-18 16:45 [PATCH 00/28] media: coda: fixes and improvements Philipp Zabel
2019-06-18 16:45 ` [PATCH 01/28] media: coda: implement CMD_START to restart decoding Philipp Zabel
2019-06-18 16:45 ` [PATCH 02/28] media: coda: use mem2mem try_en/decoder_cmd helpers Philipp Zabel
2019-06-18 16:45 ` [PATCH 03/28] media: coda: fix mpeg2 sequence number handling Philipp Zabel
2019-06-18 16:45 ` [PATCH 04/28] media: coda: fix last buffer handling in V4L2_ENC_CMD_STOP Philipp Zabel
2019-06-18 16:45 ` [PATCH 05/28] media: coda: add coda_wake_up_capture_queue Philipp Zabel
2019-06-18 16:45 ` [PATCH 06/28] media: coda: fix V4L2_DEC_CMD_STOP when all buffers are already consumed Philipp Zabel
2019-06-18 16:45 ` [PATCH 07/28] media: coda: split decoder sequence initialization out of start decoding Philipp Zabel
2019-06-18 16:45 ` Philipp Zabel [this message]
2019-06-18 16:45 ` [PATCH 09/28] media: coda: implement decoder source change event Philipp Zabel
2019-06-18 16:45 ` [PATCH 10/28] media: coda: integrate internal frame metadata into a structure Philipp Zabel
2019-06-18 16:45 ` [PATCH 11/28] media: coda: make coda_bitstream_queue more versatile Philipp Zabel
2019-06-18 16:45 ` [PATCH 12/28] media: coda: pad first buffer with repeated MPEG headers to fix sequence init Philipp Zabel
2019-06-18 16:45 ` [PATCH 13/28] media: coda: do not enforce 512-byte initial bitstream payload on CODA960 Philipp Zabel
2019-06-18 16:45 ` [PATCH 14/28] media: coda: flush bitstream ring buffer on decoder restart Philipp Zabel
2019-06-18 16:45 ` [PATCH 15/28] media: coda: increment sequence offset for the last returned frame Philipp Zabel
2019-06-18 16:45 ` [PATCH 16/28] media: coda: allow flagging last output buffer internally Philipp Zabel
2019-06-18 16:45 ` [PATCH 17/28] media: coda: mark the last output buffer on decoder stop command Philipp Zabel
2019-06-18 16:45 ` [PATCH 18/28] media: coda: only set the stream end flags if there are no more pending output buffers Philipp Zabel
2019-06-18 16:45 ` [PATCH 19/28] media: coda: mark the last output buffer on encoder stop command Philipp Zabel
2019-06-18 16:45 ` [PATCH 20/28] media: coda: retire coda_buf_is_end_of_stream Philipp Zabel
2019-06-18 16:45 ` [PATCH 21/28] media: coda: only wake up capture queue if no pending buffers to encode Philipp Zabel
2019-06-18 16:45 ` [PATCH 22/28] media: coda: flag the last encoded buffer Philipp Zabel
2019-06-18 16:45 ` [PATCH 23/28] media: coda: lock capture queue wakeup against encoder stop command Philipp Zabel
2019-06-18 16:45 ` [PATCH 24/28] media: coda: mark last pending buffer or last meta on decoder " Philipp Zabel
2019-06-18 16:45 ` [PATCH 25/28] media: coda: mark last returned frame Philipp Zabel
2019-06-18 16:45 ` [PATCH 26/28] media: coda: store device pointer in driver structure instead of pdev Philipp Zabel
2019-06-18 16:45 ` [PATCH 27/28] media: coda: add coda_slice_mode() function Philipp Zabel
2019-06-18 16:45 ` [PATCH 28/28] media: coda: encoder parameter change support Philipp Zabel

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=20190618164535.20162-9-p.zabel@pengutronix.de \
    --to=p.zabel@pengutronix.de \
    --cc=hverkuil@xs4all.nl \
    --cc=kernel@pengutronix.de \
    --cc=linux-media@vger.kernel.org \
    --cc=mchehab@kernel.org \
    /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;
as well as URLs for NNTP newsgroup(s).