All of lore.kernel.org
 help / color / mirror / Atom feed
From: Philipp Zabel <p.zabel@pengutronix.de>
To: linux-media@vger.kernel.org
Cc: Mauro Carvalho Chehab <m.chehab@samsung.com>,
	Kamil Debski <k.debski@samsung.com>,
	Fabio Estevam <fabio.estevam@freescale.com>,
	kernel@pengutronix.de, Philipp Zabel <p.zabel@pengutronix.de>
Subject: [PATCH 21/30] [media] coda: add decoder timestamp queue
Date: Fri, 13 Jun 2014 18:08:47 +0200	[thread overview]
Message-ID: <1402675736-15379-22-git-send-email-p.zabel@pengutronix.de> (raw)
In-Reply-To: <1402675736-15379-1-git-send-email-p.zabel@pengutronix.de>

The coda driver advertises timestamp_type V4L2_BUF_FLAG_TIMESTAMP_COPY on
both queues, so we have to copy timestamps from input v4l2 buffers to the
corresponding destination v4l2 buffers. Since the h.264 decoder can reorder
frames, a timestamp queue is needed to keep track of and assign the correct
timestamp to destination buffers.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
---
 drivers/media/platform/coda.c | 50 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/drivers/media/platform/coda.c b/drivers/media/platform/coda.c
index a00eaaf..9de0af0 100644
--- a/drivers/media/platform/coda.c
+++ b/drivers/media/platform/coda.c
@@ -201,6 +201,13 @@ struct gdi_tiled_map {
 #define GDI_LINEAR_FRAME_MAP 0
 };
 
+struct coda_timestamp {
+	struct list_head	list;
+	u32			sequence;
+	struct v4l2_timecode	timecode;
+	struct timeval		timestamp;
+};
+
 struct coda_ctx {
 	struct coda_dev			*dev;
 	struct mutex			buffer_mutex;
@@ -235,6 +242,8 @@ struct coda_ctx {
 	struct coda_aux_buf		slicebuf;
 	struct coda_aux_buf		internal_frames[CODA_MAX_FRAMEBUFFERS];
 	u32				frame_types[CODA_MAX_FRAMEBUFFERS];
+	struct coda_timestamp		frame_timestamps[CODA_MAX_FRAMEBUFFERS];
+	struct list_head		timestamp_list;
 	struct coda_aux_buf		workbuf;
 	int				num_internal_frames;
 	int				idx;
@@ -1067,7 +1076,7 @@ static int coda_bitstream_queue(struct coda_ctx *ctx, struct vb2_buffer *src_buf
 	dma_sync_single_for_device(&ctx->dev->plat_dev->dev, ctx->bitstream.paddr,
 				   ctx->bitstream.size, DMA_TO_DEVICE);
 
-	ctx->qsequence++;
+	src_buf->v4l2_buf.sequence = ctx->qsequence++;
 
 	return 0;
 }
@@ -1103,12 +1112,26 @@ static bool coda_bitstream_try_queue(struct coda_ctx *ctx,
 static void coda_fill_bitstream(struct coda_ctx *ctx)
 {
 	struct vb2_buffer *src_buf;
+	struct coda_timestamp *ts;
 
 	while (v4l2_m2m_num_src_bufs_ready(ctx->fh.m2m_ctx) > 0) {
 		src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 
 		if (coda_bitstream_try_queue(ctx, src_buf)) {
+			/*
+			 * Source buffer is queued in the bitstream ringbuffer;
+			 * queue the timestamp and mark source buffer as done
+			 */
 			src_buf = v4l2_m2m_src_buf_remove(ctx->fh.m2m_ctx);
+
+			ts = kmalloc(sizeof(*ts), GFP_KERNEL);
+			if (ts) {
+				ts->sequence = src_buf->v4l2_buf.sequence;
+				ts->timecode = src_buf->v4l2_buf.timecode;
+				ts->timestamp = src_buf->v4l2_buf.timestamp;
+				list_add_tail(&ts->list, &ctx->timestamp_list);
+			}
+
 			v4l2_m2m_buf_done(src_buf, VB2_BUF_STATE_DONE);
 		} else {
 			break;
@@ -2653,6 +2676,14 @@ static void coda_stop_streaming(struct vb2_queue *q)
 	}
 
 	if (!ctx->streamon_out && !ctx->streamon_cap) {
+		struct coda_timestamp *ts;
+
+		while (!list_empty(&ctx->timestamp_list)) {
+			ts = list_first_entry(&ctx->timestamp_list,
+					      struct coda_timestamp, list);
+			list_del(&ts->list);
+			kfree(ts);
+		}
 		kfifo_init(&ctx->bitstream_fifo,
 			ctx->bitstream.vaddr, ctx->bitstream.size);
 		ctx->runcounter = 0;
@@ -2940,6 +2971,7 @@ static int coda_open(struct file *file)
 		ctx->bitstream.vaddr, ctx->bitstream.size);
 	mutex_init(&ctx->bitstream_mutex);
 	mutex_init(&ctx->buffer_mutex);
+	INIT_LIST_HEAD(&ctx->timestamp_list);
 
 	coda_lock(ctx);
 	list_add(&ctx->list, &dev->instances);
@@ -3031,6 +3063,7 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 	struct coda_q_data *q_data_src;
 	struct coda_q_data *q_data_dst;
 	struct vb2_buffer *dst_buf;
+	struct coda_timestamp *ts;
 	int width, height;
 	int decoded_idx;
 	int display_idx;
@@ -3152,6 +3185,18 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 		v4l2_err(&dev->v4l2_dev,
 			 "decoded frame index out of range: %d\n", decoded_idx);
 	} else {
+		ts = list_first_entry(&ctx->timestamp_list,
+				      struct coda_timestamp, list);
+		list_del(&ts->list);
+		val = coda_read(dev, CODA_RET_DEC_PIC_FRAME_NUM) - 1;
+		if (val != ts->sequence) {
+			v4l2_err(&dev->v4l2_dev,
+				 "sequence number mismatch (%d != %d)\n",
+				 val, ts->sequence);
+		}
+		ctx->frame_timestamps[decoded_idx] = *ts;
+		kfree(ts);
+
 		val = coda_read(dev, CODA_RET_DEC_PIC_TYPE) & 0x7;
 		if (val == 0)
 			ctx->frame_types[decoded_idx] = V4L2_BUF_FLAG_KEYFRAME;
@@ -3184,6 +3229,9 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 		dst_buf->v4l2_buf.flags &= ~(V4L2_BUF_FLAG_KEYFRAME |
 					     V4L2_BUF_FLAG_PFRAME);
 		dst_buf->v4l2_buf.flags |= ctx->frame_types[ctx->display_idx];
+		ts = &ctx->frame_timestamps[ctx->display_idx];
+		dst_buf->v4l2_buf.timecode = ts->timecode;
+		dst_buf->v4l2_buf.timestamp = ts->timestamp;
 
 		vb2_set_plane_payload(dst_buf, 0, width * height * 3 / 2);
 
-- 
2.0.0.rc2


  parent reply	other threads:[~2014-06-13 16:09 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2014-06-13 16:08 [PATCH 00/30] Initial CODA960 (i.MX6 VPU) support Philipp Zabel
2014-06-13 16:08 ` [PATCH 01/30] [media] coda: fix decoder I/P/B frame detection Philipp Zabel
2014-06-16  7:54   ` Hans Verkuil
2014-06-13 16:08 ` [PATCH 02/30] [media] coda: fix readback of CODA_RET_DEC_SEQ_FRAME_NEED Philipp Zabel
2014-06-13 16:08 ` [PATCH 03/30] [media] coda: fix h.264 quantization parameter range Philipp Zabel
2014-06-13 16:08 ` [PATCH 04/30] [media] coda: fix internal framebuffer allocation size Philipp Zabel
2014-06-13 16:08 ` [PATCH 05/30] [media] coda: simplify IRAM setup Philipp Zabel
2014-06-13 16:08 ` [PATCH 06/30] [media] coda: Add encoder/decoder support for CODA960 Philipp Zabel
2014-06-24 15:53   ` Nicolas Dufresne
2014-07-01 17:52     ` Philipp Zabel
2014-06-13 16:08 ` [PATCH 07/30] [media] coda: add selection API support for h.264 decoder Philipp Zabel
2014-06-16  8:05   ` Hans Verkuil
2014-06-13 16:08 ` [PATCH 08/30] [media] coda: add support for frame size enumeration Philipp Zabel
2014-06-16  8:08   ` Hans Verkuil
2014-06-24 15:13     ` Philipp Zabel
2014-06-13 16:08 ` [PATCH 09/30] [media] coda: add workqueue to serialize hardware commands Philipp Zabel
2014-06-13 16:08 ` [PATCH 10/30] [media] coda: Use mem-to-mem ioctl helpers Philipp Zabel
2014-06-13 16:08 ` [PATCH 11/30] [media] coda: use ctx->fh.m2m_ctx instead of ctx->m2m_ctx Philipp Zabel
2014-06-13 16:08 ` [PATCH 12/30] [media] coda: Add runtime pm support Philipp Zabel
2014-06-13 16:56   ` Sylwester Nawrocki
2014-06-13 21:07     ` Philipp Zabel
2014-06-13 16:08 ` [PATCH 13/30] [media] coda: split firmware version check out of coda_hw_init Philipp Zabel
2014-06-13 16:08 ` [PATCH 14/30] [media] coda: select GENERIC_ALLOCATOR Philipp Zabel
2014-06-13 16:08 ` [PATCH 15/30] [media] coda: add h.264 min/max qp controls Philipp Zabel
2014-06-13 16:08 ` [PATCH 16/30] [media] coda: add h.264 deblocking filter controls Philipp Zabel
2014-06-13 16:08 ` [PATCH 17/30] [media] coda: add cyclic intra refresh control Philipp Zabel
2014-06-13 16:08 ` [PATCH 18/30] [media] coda: let userspace force IDR frames by enabling the keyframe flag in the source buffer Philipp Zabel
2014-06-16  8:24   ` Hans Verkuil
2014-06-24 15:16     ` Philipp Zabel
2014-06-13 16:08 ` [PATCH 19/30] [media] v4l2-mem2mem: export v4l2_m2m_try_schedule Philipp Zabel
2014-06-13 16:08 ` [PATCH 20/30] [media] coda: try to schedule a decode run after a stop command Philipp Zabel
2014-06-13 16:08 ` Philipp Zabel [this message]
2014-06-13 16:08 ` [PATCH 22/30] [media] coda: alert userspace about macroblock errors Philipp Zabel
2014-06-13 16:08 ` [PATCH 23/30] [media] coda: add sequence counter offset Philipp Zabel
2014-06-13 16:08 ` [PATCH 24/30] [media] coda: use prescan_failed variable to stop stream after a timeout Philipp Zabel
2014-06-13 16:08 ` [PATCH 25/30] [media] coda: add reset control support Philipp Zabel
2014-06-13 16:08 ` [PATCH 26/30] [media] coda: add bytesperline to queue data Philipp Zabel
2014-06-13 16:08 ` [PATCH 27/30] [media] coda: allow odd width, but still round up bytesperline Philipp Zabel
2014-06-13 16:08 ` [PATCH 28/30] [media] coda: round up internal frames to multiples of macroblock size for h.264 Philipp Zabel
2014-06-13 16:08 ` [PATCH 29/30] [media] coda: increase frame stride to 16 " Philipp Zabel
2014-06-13 16:08 ` [PATCH 30/30] [media] coda: export auxiliary buffers via debugfs Philipp Zabel
2014-06-16  8:35 ` [PATCH 00/30] Initial CODA960 (i.MX6 VPU) support Hans Verkuil
2014-06-24 15:07   ` Philipp Zabel
2014-06-27  9:14     ` Hans Verkuil

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=1402675736-15379-22-git-send-email-p.zabel@pengutronix.de \
    --to=p.zabel@pengutronix.de \
    --cc=fabio.estevam@freescale.com \
    --cc=k.debski@samsung.com \
    --cc=kernel@pengutronix.de \
    --cc=linux-media@vger.kernel.org \
    --cc=m.chehab@samsung.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.