ac1658f86615853e66b67318a48a38bd831d73bd
[openwrt/staging/blogic.git] /
1 From 4fb4bf2f8e88973a4b575b537c774dd563160c5f Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Mon, 28 Mar 2022 11:52:48 +0100
4 Subject: [PATCH] bcm2835-codec: Return empty buffers to the VPU
5 instead of queueing to vbuf2
6
7 The encoder can skip frames totally should rate control overshoot
8 the target bitrate too far. In this situation it generates an
9 output buffer of length 0.
10 V4L2 treats a buffer of length 0 as an end of stream flag, which is
11 not appropriate in this case, therefore we can not return that buffer
12 to the client.
13
14 The driver was returning the buffer to videobuf2 in the QUEUED state,
15 however that buffer was then not dequeued again, so the number of
16 buffers was reduced each time this happened. In the pathological
17 case of using GStreamer's videotestsrc in mode 1 for noise, this happens
18 sufficiently frequently to totally stall the pipeline.
19
20 If the port is still enabled then return the buffer straight back to
21 the VPU rather than to videobuf2.
22
23 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
24 ---
25 .../bcm2835-codec/bcm2835-v4l2-codec.c | 13 +++++++++----
26 1 file changed, 9 insertions(+), 4 deletions(-)
27
28 --- a/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
29 +++ b/drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c
30 @@ -1159,10 +1159,15 @@ static void op_buffer_cb(struct vchiq_mm
31 v4l2_dbg(2, debug, &ctx->dev->v4l2_dev, "%s: Empty buffer - flags %04x",
32 __func__, mmal_buf->mmal_flags);
33 if (!(mmal_buf->mmal_flags & MMAL_BUFFER_HEADER_FLAG_EOS)) {
34 - vb2_buffer_done(&vb2->vb2_buf, VB2_BUF_STATE_QUEUED);
35 - if (!port->enabled &&
36 - atomic_read(&port->buffers_with_vpu))
37 - complete(&ctx->frame_cmplt);
38 + if (!port->enabled) {
39 + vb2_buffer_done(&vb2->vb2_buf, VB2_BUF_STATE_QUEUED);
40 + if (atomic_read(&port->buffers_with_vpu))
41 + complete(&ctx->frame_cmplt);
42 + } else {
43 + vchiq_mmal_submit_buffer(ctx->dev->instance,
44 + &ctx->component->output[0],
45 + mmal_buf);
46 + }
47 return;
48 }
49 }