staging: vc04_service: codec: Allow start_streaming to update the buffernum 08/249308/1
authorDave Stevenson <dave.stevenson@raspberrypi.com>
Thu, 13 Aug 2020 16:01:27 +0000 (17:01 +0100)
committerSeung-Woo Kim <sw0312.kim@samsung.com>
Thu, 10 Dec 2020 04:14:02 +0000 (13:14 +0900)
start_streaming passes a count of how many buffers have been queued
to videobuf2.

Allow this value to update the number of buffers the VPU allocates
on a port to avoid buffer recycling issues.

Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
[sw0312.kim: cherry-pick rpi-5.4.y commit to fix video decoding seek issue]
Ref: https://github.com/raspberrypi/linux/pull/3790
Signed-off-by: Seung-Woo Kim <sw0312.kim@samsung.com>
Change-Id: Iaf37f57df95789cc8987b268feab1f0fa7377849

drivers/staging/vc04_services/bcm2835-codec/bcm2835-v4l2-codec.c

index b6c5a66..427048c 100644 (file)
@@ -2268,6 +2268,7 @@ static int bcm2835_codec_start_streaming(struct vb2_queue *q,
        struct bcm2835_codec_ctx *ctx = vb2_get_drv_priv(q);
        struct bcm2835_codec_dev *dev = ctx->dev;
        struct bcm2835_codec_q_data *q_data = get_q_data(ctx, q->type);
+       struct vchiq_mmal_port *port = get_port_data(ctx, q->type);
        int ret;
 
        v4l2_dbg(1, debug, &ctx->dev->v4l2_dev, "%s: type: %d count %d\n",
@@ -2283,6 +2284,20 @@ static int bcm2835_codec_start_streaming(struct vb2_queue *q,
                ctx->component_enabled = true;
        }
 
+       if (count < port->minimum_buffer.num)
+               count = port->minimum_buffer.num;
+
+       if (port->current_buffer.num != count + 1) {
+               v4l2_dbg(2, debug, &ctx->dev->v4l2_dev, "%s: ctx:%p, buffer count changed %u to %u\n",
+                        __func__, ctx, port->current_buffer.num, count + 1);
+
+               port->current_buffer.num = count + 1;
+               ret = vchiq_mmal_port_set_format(dev->instance, port);
+               if (ret)
+                       v4l2_err(&ctx->dev->v4l2_dev, "%s: Error updating buffer count, ret %d\n",
+                                __func__, ret);
+       }
+
        if (q->type == V4L2_BUF_TYPE_VIDEO_OUTPUT_MPLANE) {
                /*
                 * Create the EOS buffer.
@@ -2294,17 +2309,17 @@ static int bcm2835_codec_start_streaming(struct vb2_queue *q,
                                      &q_data->eos_buffer.mmal);
                q_data->eos_buffer_in_use = false;
 
-               ctx->component->input[0].cb_ctx = ctx;
+               port->cb_ctx = ctx;
                ret = vchiq_mmal_port_enable(dev->instance,
-                                            &ctx->component->input[0],
+                                            port,
                                             ip_buffer_cb);
                if (ret)
                        v4l2_err(&ctx->dev->v4l2_dev, "%s: Failed enabling i/p port, ret %d\n",
                                 __func__, ret);
        } else {
-               ctx->component->output[0].cb_ctx = ctx;
+               port->cb_ctx = ctx;
                ret = vchiq_mmal_port_enable(dev->instance,
-                                            &ctx->component->output[0],
+                                            port,
                                             op_buffer_cb);
                if (ret)
                        v4l2_err(&ctx->dev->v4l2_dev, "%s: Failed enabling o/p port, ret %d\n",