]> git.proxmox.com Git - mirror_ubuntu-eoan-kernel.git/commitdiff
media: coda: flush bitstream ring buffer on decoder restart
authorPhilipp Zabel <p.zabel@pengutronix.de>
Tue, 18 Jun 2019 16:45:21 +0000 (12:45 -0400)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Mon, 24 Jun 2019 18:31:50 +0000 (14:31 -0400)
The bitstream ringbuffer might be in an underrun state after draining,
or it might still contain unread data if the previous decoder stop
command was flagged as immediate. Flush the bitstream ring buffer
during V4L2_DEC_CMD_START to get into a well defined state. Also fill
the bitstream with buffers that have been queued during draining,
to resume decoding immediately.

Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/coda/coda-bit.c
drivers/media/platform/coda/coda-common.c
drivers/media/platform/coda/coda.h

index 5a1016243032a0978fab0fff39c425923ab24c2e..843f92312f4793a5ec20bf9158d7225c47a2af12 100644 (file)
@@ -199,6 +199,26 @@ static int coda_h264_bitstream_pad(struct coda_ctx *ctx, u32 size)
        return (n < size) ? -ENOSPC : 0;
 }
 
+int coda_bitstream_flush(struct coda_ctx *ctx)
+{
+       int ret;
+
+       if (ctx->inst_type != CODA_INST_DECODER || !ctx->use_bit)
+               return 0;
+
+       ret = coda_command_sync(ctx, CODA_COMMAND_DEC_BUF_FLUSH);
+       if (ret < 0) {
+               v4l2_err(&ctx->dev->v4l2_dev, "failed to flush bitstream\n");
+               return ret;
+       }
+
+       kfifo_init(&ctx->bitstream_fifo, ctx->bitstream.vaddr,
+                  ctx->bitstream.size);
+       coda_kfifo_sync_to_device_full(ctx);
+
+       return 0;
+}
+
 static int coda_bitstream_queue(struct coda_ctx *ctx, const u8 *buf, u32 size)
 {
        u32 n = kfifo_in(&ctx->bitstream_fifo, buf, size);
index 1f1eb9685bc49ed38cb3705e6d4eeaa9ce6a69ee..0f5e6dcded991396e30ea1e34040b24d5368f854 100644 (file)
@@ -1052,6 +1052,7 @@ static int coda_decoder_cmd(struct file *file, void *fh,
                            struct v4l2_decoder_cmd *dc)
 {
        struct coda_ctx *ctx = fh_to_ctx(fh);
+       struct coda_dev *dev = ctx->dev;
        struct vb2_queue *dst_vq;
        int ret;
 
@@ -1061,10 +1062,16 @@ static int coda_decoder_cmd(struct file *file, void *fh,
 
        switch (dc->cmd) {
        case V4L2_DEC_CMD_START:
+               mutex_lock(&ctx->bitstream_mutex);
+               mutex_lock(&dev->coda_mutex);
+               coda_bitstream_flush(ctx);
+               mutex_unlock(&dev->coda_mutex);
                dst_vq = v4l2_m2m_get_vq(ctx->fh.m2m_ctx,
                                         V4L2_BUF_TYPE_VIDEO_CAPTURE);
                vb2_clear_last_buffer_dequeued(dst_vq);
                ctx->bit_stream_param &= ~CODA_BIT_STREAM_END_FLAG;
+               coda_fill_bitstream(ctx, NULL);
+               mutex_unlock(&ctx->bitstream_mutex);
                break;
        case V4L2_DEC_CMD_STOP:
                /* Set the stream-end flag on this context */
index 12bbd3129269e12cf409ab83ae6df42b5697d374..6911c1c811cefe735df8743634b4343f3e7e3a4c 100644 (file)
@@ -322,6 +322,7 @@ static inline bool coda_bitstream_can_fetch_past(struct coda_ctx *ctx,
 }
 
 bool coda_bitstream_can_fetch_past(struct coda_ctx *ctx, unsigned int pos);
+int coda_bitstream_flush(struct coda_ctx *ctx);
 
 void coda_bit_stream_end_flag(struct coda_ctx *ctx);