]> asedeno.scripts.mit.edu Git - linux.git/commitdiff
media: coda: limit queueing into internal bitstream buffer
authorLucas Stach <l.stach@pengutronix.de>
Mon, 5 Nov 2018 15:25:02 +0000 (10:25 -0500)
committerMauro Carvalho Chehab <mchehab+samsung@kernel.org>
Fri, 23 Nov 2018 10:27:05 +0000 (05:27 -0500)
The ringbuffer used to hold the bitstream is very conservatively sized,
as keyframes can get very large and still need to fit into this buffer.
This means that the buffer is way oversized for the average stream to
the extend that it will hold a few hundred frames when the video data
is compressing well.

The current strategy of queueing as much bitstream data as possible
leads to large delays when draining the decoder. In order to keep the
drain latency to a reasonable bound, try to only queue a full reorder
window of buffers. We can't always hit this low target for very well
compressible video data, as we might end up with less than the minimum
amount of data that needs to be available to the bitstream prefetcher,
so we must take this into account and allow more buffers to be queued
in this case.

Signed-off-by: Lucas Stach <l.stach@pengutronix.de>
Signed-off-by: Philipp Zabel <p.zabel@pengutronix.de>
Signed-off-by: Hans Verkuil <hansverk@cisco.com>
Signed-off-by: Mauro Carvalho Chehab <mchehab+samsung@kernel.org>
drivers/media/platform/coda/coda-bit.c

index e5ce0bec8ec39f133b518d2c0be82f62f1ff1d06..ee9d2a402ccdeaebb885d7404b61e796625465f4 100644 (file)
@@ -269,6 +269,23 @@ void coda_fill_bitstream(struct coda_ctx *ctx, struct list_head *buffer_list)
                    ctx->num_metas > 1)
                        break;
 
+               if (ctx->num_internal_frames &&
+                   ctx->num_metas >= ctx->num_internal_frames) {
+                       meta = list_first_entry(&ctx->buffer_meta_list,
+                                               struct coda_buffer_meta, list);
+
+                       /*
+                        * If we managed to fill in at least a full reorder
+                        * window of buffers (num_internal_frames is a
+                        * conservative estimate for this) and the bitstream
+                        * prefetcher has at least 2 256 bytes periods beyond
+                        * the first buffer to fetch, we can safely stop queuing
+                        * in order to limit the decoder drain latency.
+                        */
+                       if (coda_bitstream_can_fetch_past(ctx, meta->end))
+                               break;
+               }
+
                src_buf = v4l2_m2m_next_src_buf(ctx->fh.m2m_ctx);
 
                /* Drop frames that do not start/end with a SOI/EOI markers */
@@ -2252,6 +2269,17 @@ static void coda_finish_decode(struct coda_ctx *ctx)
 
        /* The rotator will copy the current display frame next time */
        ctx->display_idx = display_idx;
+
+       /*
+        * The current decode run might have brought the bitstream fill level
+        * below the size where we can start the next decode run. As userspace
+        * might have filled the output queue completely and might thus be
+        * blocked, we can't rely on the next qbuf to trigger the bitstream
+        * refill. Check if we have data to refill the bitstream now.
+        */
+       mutex_lock(&ctx->bitstream_mutex);
+       coda_fill_bitstream(ctx, NULL);
+       mutex_unlock(&ctx->bitstream_mutex);
 }
 
 static void coda_decode_timeout(struct coda_ctx *ctx)