media: cedrus: Allow using the current dst buffer as reference
authorPaul Kocialkowski <paul.kocialkowski@bootlin.com>
Wed, 9 Jan 2019 14:19:20 +0000 (12:19 -0200)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 21 Jan 2019 17:43:42 +0000 (15:43 -0200)
It was reported that some cases of interleaved video decoding require
using the current destination buffer as a reference. However, this is
no longer possible after the move to vb2_find_timestamp because only
dequeued and done buffers are considered.

Add a helper in our driver that also considers the current destination
buffer before resorting to vb2_find_timestamp and use it in MPEG-2.

Signed-off-by: Paul Kocialkowski <paul.kocialkowski@bootlin.com>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/staging/media/sunxi/cedrus/cedrus_dec.c
drivers/staging/media/sunxi/cedrus/cedrus_dec.h
drivers/staging/media/sunxi/cedrus/cedrus_mpeg2.c

index 443fb037e1cf2d65c057ef27ad93364b3f9ca1f1..2c295286766cc0dd785bce070a8dd7171bd6be92 100644 (file)
 #include "cedrus_dec.h"
 #include "cedrus_hw.h"
 
+int cedrus_reference_index_find(struct vb2_queue *queue,
+                               struct vb2_buffer *vb2_buf, u64 timestamp)
+{
+       /*
+        * Allow using the current capture buffer as reference, which can occur
+        * for field-coded pictures.
+        */
+       if (vb2_buf->timestamp == timestamp)
+               return vb2_buf->index;
+       else
+               return vb2_find_timestamp(queue, timestamp, 0);
+}
+
 void cedrus_device_run(void *priv)
 {
        struct cedrus_ctx *ctx = priv;
index d1ae7903677bf2b7487003c719352c26fdb9c770..8d0fc248220f79621bd75ba61166cfa48d012f52 100644 (file)
@@ -16,6 +16,8 @@
 #ifndef _CEDRUS_DEC_H_
 #define _CEDRUS_DEC_H_
 
+int cedrus_reference_index_find(struct vb2_queue *queue,
+                               struct vb2_buffer *vb2_buf, u64 timestamp);
 void cedrus_device_run(void *priv);
 
 #endif
index cb45fda9aaeb0519e1402f84cb34932e6d49d268..81c66a8aa1acab10989b0b271d8a9a0eb60c2488 100644 (file)
@@ -10,6 +10,7 @@
 #include <media/videobuf2-dma-contig.h>
 
 #include "cedrus.h"
+#include "cedrus_dec.h"
 #include "cedrus_hw.h"
 #include "cedrus_regs.h"
 
@@ -159,8 +160,8 @@ static void cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
        cedrus_write(dev, VE_DEC_MPEG_PICBOUNDSIZE, reg);
 
        /* Forward and backward prediction reference buffers. */
-       forward_idx = vb2_find_timestamp(cap_q,
-                                        slice_params->forward_ref_ts, 0);
+       forward_idx = cedrus_reference_index_find(cap_q, &run->dst->vb2_buf,
+                                                 slice_params->forward_ref_ts);
 
        fwd_luma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 0);
        fwd_chroma_addr = cedrus_dst_buf_addr(ctx, forward_idx, 1);
@@ -168,8 +169,9 @@ static void cedrus_mpeg2_setup(struct cedrus_ctx *ctx, struct cedrus_run *run)
        cedrus_write(dev, VE_DEC_MPEG_FWD_REF_LUMA_ADDR, fwd_luma_addr);
        cedrus_write(dev, VE_DEC_MPEG_FWD_REF_CHROMA_ADDR, fwd_chroma_addr);
 
-       backward_idx = vb2_find_timestamp(cap_q,
-                                         slice_params->backward_ref_ts, 0);
+       backward_idx = cedrus_reference_index_find(cap_q, &run->dst->vb2_buf,
+                                                  slice_params->backward_ref_ts);
+
        bwd_luma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 0);
        bwd_chroma_addr = cedrus_dst_buf_addr(ctx, backward_idx, 1);